Search Results

Search found 2819 results on 113 pages for 'conditional expressions'.

Page 20/113 | < Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >

  • wordpress conditional statements

    - by codedude
    I am using this code in wordpress to display different content when different pages are loaded. I have 5 pages on the site called Home, Bio, Work, Contact and Notes. The Notes page is being used as a blog. Here is the code I am using. <?php if (is_page('contact')) { ?> get in touch with me <?php } elseif (is_single()) { ?> a note from me <?php } elseif (is_page('notes')) { ?> the notes of me <?php } else { ?> the <?php the_title(); ?> of me <?php } ?> So if it the contact page, it displays "get in touch with me" and if it is a single blog post page it displays "a note from me". However this is where I have a problem. The next statement should display "the notes of me" when it is on the Notes page. However, this does not happen. Instead it shows the default content which is in the "else" statement. any idea on why this is happening?

    Read the article

  • SQL: Recursively get parent records using Common Table Expressions

    - by Martijn B
    Hi there, Suposse you have to following tables where a sale consists of products and a product can be placed in multiple categories. Whereby categories have a hierachly structure like: Man Shoes Sport Casual Watches Women Shoes Sport Casual Watches Tables: Sale: id name 1 Sale1 Product: id saleidfk name 1 1 a 2 1 b 3 1 c 4 1 d 5 1 e ProductCategory : productid categoryid 1 3 2 3 3 4 4 5 5 10 Category: id ParentCategoryIdFk name 1 null Men 2 1 Shoes 3 2 Sport 4 2 Casual 5 1 Watches 6 null Women 7 6 Shoes 8 7 Sport 9 7 Casual 10 6 Watches Question: Now on my website I want to create a control where only the categories are shown of a certain sale and where the categories are filled with the products of the sale. I also want to include the hierachly structure of the categories. So if we have a leave node, recusivly go up to the top node. So with sale1 I should have a query with the following result: Men Shoes Sport Casual Watches Women Watches This thing is driving me crazy :-) Thanks in advance! Gr Martijn

    Read the article

  • Merging two Regular Expressions to Truncate Words in Strings

    - by Alix Axel
    I'm trying to come up with the following function that truncates string to whole words (if possible, otherwise it should truncate to chars): function Text_Truncate($string, $limit, $more = '...') { $string = trim(html_entity_decode($string, ENT_QUOTES, 'UTF-8')); if (strlen(utf8_decode($string)) > $limit) { $string = preg_replace('~^(.{1,' . intval($limit) . '})(?:\s.*|$)~su', '$1', $string); if (strlen(utf8_decode($string)) > $limit) { $string = preg_replace('~^(.{' . intval($limit) . '}).*~su', '$1', $string); } $string .= $more; } return trim(htmlentities($string, ENT_QUOTES, 'UTF-8', true)); } Here are some tests: // Iñtërnâtiônàlizætiøn and then the quick brown fox... (49 + 3 chars) echo dyd_Text_Truncate('Iñtërnâtiônàlizætiøn and then the quick brown fox jumped overly the lazy dog and one day the lazy dog humped the poor fox down until she died.', 50, '...'); // Iñtërnâtiônàlizætiøn_and_then_the_quick_brown_fox_... (50 + 3 chars) echo dyd_Text_Truncate('Iñtërnâtiônàlizætiøn_and_then_the_quick_brown_fox_jumped_overly_the_lazy_dog and one day the lazy dog humped the poor fox down until she died.', 50, '...'); They both work as it is, however if I drop the second preg_replace() I get the following: Iñtërnâtiônàlizætiøn_and_then_the_quick_brown_fox_jumped_overly_the_lazy_dog and one day the lazy dog humped the poor fox down until she died.... I can't use substr() because it only works on byte level and I don't have access to mb_substr() ATM, I've made several attempts to join the second regex with the first one but without success. Please help S.M.S., I've been struggling with this for almost an hour. EDIT: I'm sorry, I've been awake for 40 hours and I shamelessly missed this: $string = preg_replace('~^(.{1,' . intval($limit) . '})(?:\s.*|$)?~su', '$1', $string); Still, if someone has a more optimized regex (or one that ignores the trailing space) please share: "Iñtërnâtiônàlizætiøn and then " "Iñtërnâtiônàlizætiøn_and_then_" EDIT 2: I still can't get rid of the trailing whitespace, can someone help me out?

    Read the article

  • VBScript + Regular Expressions

    - by Karthik
    Dim sString sString = "John;Mary;Anne;Adam;Bill;Ester" Is there a regex I can use to retrieve the following from the above list: John (; at the end of the name) Anne (; at the beginning and end) Ester (; at the beginning) I am currently using the following regex for each: 1. Joh.* 2. .*An.* 3. .*st.* But, the above retrieves the entire string instead of the values I want. How can I get the correct values? Code: Dim oRegex : Set oRegex = New RegExp oRegex.Global = False oRegex.IgnoreCase = False 'John oRegex.Pattern = "Joh.*" Set oMatch = oRegex.Execute(sString) sName = oMatch(0) The above code retrieves the entire string, instead of only John. Same issue with the others :(

    Read the article

  • Conditional ESC, ideas?

    - by Tony
    I often need to enter insert mode just to make changes on a specific line, and would like know if there is a way to enter insert mode in a way that when I am done editing on that line, hitting [Return] gets me back to normal mode. I am aware of the 'r' command for replacing a single character, I guess what I want is something like that but for a line.

    Read the article

  • Converting F# Quotations into LINQ Expressions

    - by forki23
    Hi, I can convert a quotation of type Expr<'a -> 'b> to a Linq expression via the following snippet: /// Converts a F# Expression to a LINQ Lambda let toLambda (exp:Expr) = let linq = exp.ToLinqExpression() :?> MethodCallExpression linq.Arguments.[0] :?> LambdaExpression /// Converts a Lambda quotation into a Linq Lamba Expression with 1 parameter let ToLinq (exp : Expr<'a -> 'b>) = let lambda = toLambda exp Expression.Lambda<Func<'a, 'b>>(lambda.Body, lambda.Parameters) Now I want to convert a quotation of type Expr<'a * 'b -> 'c> or maybe even Expr<'a -> 'b -> 'c> to a Linq Lambda Expression of type Expression<Func<'a,'b'c>>. How can I do this? Regards, forki

    Read the article

  • Is there a compelling reason to use quantifiers in Perl regular expressions instead of just repeatin

    - by Morinar
    I was performing a code review for a colleague and he had a regular expression that looked like this: if ($value =~ /^\d\d\d\d$/) { #do stuff } I told him he should change it to: if ($value =~ /^\d{4}$/) { #do stuff } To which he replied that he preferred the first for readability (I find the second more readable, but that's a religious debate I'll save for another day). My question: is there an actual benefit to one over the other?

    Read the article

  • Dynamic find methods Vs conditional statements in rails

    - by piemesons
    Hello Student.find_all_by_name_and_status(‘mohit’, 1) As this will create a exception 'No method exception' first then it will be handled by dynamic Method handler and this will not Student.find(:all, :conditions => [‘name = ? and status = ?’ ‘mohit’, 1]) Does Student.find(1) Will generate method missing exception and will it prevent SQL injection?

    Read the article

  • Regular Expressions, Checking for a range of occurrences

    - by gmcalab
    I have a phone number I want to match against a regular expression. The format of the phone number must match this: (123) 123-4567 x12345 The extension is optional. Also the extension must contain 1-5 numbers. Below is a regular expression I wrote that works. ^\(\d{3}\) \d{3}-\d{4}( x\d\d?\d?\d?\d?)?$ I was wondering if there is a better way to check for the extension instead of x\d\d?\d?\d?\d? Can I say 1-5 occurrences of \d instead of the above some how ?

    Read the article

  • Swing: Scroll to bottom of JScrollPane, conditional on current viewport location

    - by I82Much
    Hi all, I am attempting to mimic the functionality of Adium and most other chat clients I've seen, wherein the scrollbars advance to the bottom when new messages come in, but only if you're already there. In other words, if you've scrolled a few lines up and are reading, when a new message comes in it won't jump your position to the bottom of the screen; that would be annoying. But if you're scrolled to the bottom, the program rightly assumes that you want to see the most recent messages at all times, and so auto-scrolls accordingly. I have had a bear of a time trying to mimic this; the platform seems to fight this behavior at all costs. The best I can do is as follows: In constructor: JTextArea chatArea = new JTextArea(); JScrollPane chatAreaScrollPane = new JScrollPane(chatArea); // We will manually handle advancing chat window DefaultCaret caret = (DefaultCaret) chatArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); In method that handles new text coming in: boolean atBottom = isViewAtBottom(); // Append the text using styles etc to the chatArea if (atBottom) { scrollViewportToBottom(); } public boolean isAtBottom() { // Is the last line of text the last line of text visible? Adjustable sb = chatAreaScrollPane.getVerticalScrollBar(); int val = sb.getValue(); int lowest = val + sb.getVisibleAmount(); int maxVal = sb.getMaximum(); boolean atBottom = maxVal == lowest; return atBottom; } private void scrollToBottom() { chatArea.setCaretPosition(chatArea.getDocument().getLength()); } Now, this works, but it's janky and not ideal for two reasons. By setting the caret position, whatever selection the user may have in the chat area is erased. I can imagine this would be very irritating if he's attempting to copy/paste. Since the advancement of the scroll pane occurs after the text is inserted, there is a split second where the scrollbar is in the wrong position, and then it visually jumps towards the end. This is not ideal. Before you ask, yes I've read this blog post on Text Area Scrolling, but the default scroll to bottom behavior is not what I want. Other related (but to my mind, not completely helpful in this regard) questions: Setting scroll bar on a jscrollpane Making a JScrollPane automatically scroll all the way down. Any help in this regard would be very much appreciated.

    Read the article

  • Django and conditional aggregates

    - by piquadrat
    I have two models, authors and articles: class Author(models.Model): name = models.CharField('name', max_length=100) class Article(models.Model) title = models.CharField('title', max_length=100) pubdate = models.DateTimeField('publication date') authors = models.ManyToManyField(Author) Now I want to select all authors and annotate them with their respective article count. That's a piece of cake with Django's aggregates. Problem is, it should only count the articles that are already published. According to ticket 11305 in the Django ticket tracker, this is not yet possible. I tried to use the CountIf annotation mentioned in that ticket, but it doesn't quote the datetime string and doesn't make all the joins it would need. So, what's the best solution, other than writing custom SQL?

    Read the article

  • Intersection of two regular expressions

    - by Henry
    Hi, Im looking for function (PHP will be the best), which returns true whether exists string matches both regexpA and regexpB. Example 1: $regexpA = '[0-9]+'; $regexpB = '[0-9]{2,3}'; hasRegularsIntersection($regexpA,$regexpB) returns TRUE because '12' matches both regexps Example 2: $regexpA = '[0-9]+'; $regexpB = '[a-z]+'; hasRegularsIntersection($regexpA,$regexpB) returns FALSE because numbers never matches literals. Thanks for any suggestions how to solve this. Henry

    Read the article

  • PDO update with conditional?

    - by dmontain
    I have a PDO mysql that updates 3 fields. $update = $mypdo->prepare("UPDATE tablename SET field1=:field1, field2=:field2, field3=:field3 WHERE key=:key"); But I want field3 to be updated only when $update3 = true; Is this possible to accomplish with a single query? I could do it with 2 queries where I update field1 and field2 then check the boolean and update field3 if needed in a separate query. But hopefully there is a way to accomplish this in 1 query?

    Read the article

  • Destructuring assignment in generator expressions and array comprehensions

    - by Eli Grey
    Why does for ([] in object); work fine but [void 0 for ([] in object)] or (void 0 for ([] in object)) throw a syntax error for invalid left-hand assignment? For example, I would expect the following code to work, but it doesn't (the assertion isn't even done due to the syntax error): let ( i = 0, arr = [1, 2, 3, 4], gen = (i for (i in arr) if (arr.hasOwnProperty(i)) ) { for ([] in gen) i++; console.assertEquals([void 0 for ([] in gen)].length, i); }

    Read the article

  • conditional selection of decimal-format in xslt

    - by Jose L Martinez-Avial
    Hi all, I'm trying to modify the decimal-format of a stylesheet based on certain information of an XML. More exaclty, I've a XML like this <?xml version="1.0" encoding="ISO-8859-1"?> <REPORT> <LANGUAGE>2</LANGUAGE> <MYVALUE>123456.78</MYVALUE> </REPORT> I'm trying to define the decimal format as european if the language is 2, and default otherwse. So I've created the following template <xsl:template match="REPORT"> <xsl:if test="$language=2"> <xsl:decimal-format decimal-separator=',' grouping-separator='.' /> </xsl:if> <xsl:value-of select ="format-number(MYVALUE,'###.###,00')"/> </xsl:template> So it shows the number in european format or in standard format. But I'm getting the following error xsl:decimal-format is not allowed in this position in the stylesheet! If I try to put the decimal-format outside the template, then I get the message that the xsl:if is not allowed in this position in the sthylsheet. How can I change the decimal-format based in the XML? Thanks Jose

    Read the article

  • When should you use intermediate variables for expressions?

    - by froadie
    There are times that one writes code such as this: callSomeMethod(someClass.someClassMethod()); And other times when one would write the same code like this: int result = someClass.someClassMethod(); callSomeMethod(result); This is just a basic example to illustrate the point. My question isn't if you should use an intermediate variable or not, as that depends on the code and can sometimes be a good design decision and sometimes a terrible one. The question is - when would you choose one method over the other? What factors would you consider when deciding whether to use an intermediate step? (I'd assume length and understandability of the fully inlined code would have something to do with it...)

    Read the article

  • Create table from a business object with conditional layout

    - by Simon Martin
    I need to generate a table from a List(Of Students). My Student class has properties for AcademicYear, TeachingSet, Surname and Forenames, is sorted in that order and also properties for ID and start date. The table should nest TeachingSets within AcademicYears and then the students within the TeachingSets, as shown in the table I've mocked up at http://www.ifslearning.ac.uk/files/student-table.jpg Using a repeater I get 08-10 students B74394 Mzejb Bsppn 08-10 students B74395 Lbuifsjof Bvti 08-10 students C68924 Epoob Cmpblf 08-10 students D41468 Ipxbse Dbwfz But I need to have 08-10 students - B74394 Mzejb Bsppn - B74395 Lbuifsjof Bvti - C68924 Epoob Cmpblf - D41468 Ipxbse Dbwfz

    Read the article

  • Regular expressions help

    - by Michael
    If I had the following HTML: <li><a href="aaa"> Thisislink1</a></li> <li><a href="abcdef"> Thisisanotherlink</a></li> <li><a href="12345"> Onemorelink</a></li> Where each link will be different in length and value. How can I search for the values inside the link (IE: Thisislink1, Thisisanotherlink and Onemorelink) with a search phrase, say 'another'. So in this example, only 'Thisisanotherlink' would be returned, but if I changed the search phrase to 'link', then all 3 values will be returned.

    Read the article

  • How to write a virtual conditional breakpoint in java

    - by Phuong Nguyen de ManCity fan
    I'm sorry if the question title may mis-inform you, but I cannot find a proper word to explain that. If you ever working with .NET, you would know that there is Assert class that will automatically wake up and attach debugger if necessary and then have debugger (Visual Studio) pausing at the Assert command, given the Assert command failed. Given I'm running a java program and having debugger connected, then how can I have debugger to break on certain condition without manually setup a break point? I'm expecting something like that: void doSomeThing(String x){ if (x==null) breakDebuggerNow(); }

    Read the article

  • boost::lambda bind expressions can't get bind to string's empty() to work

    - by navigator
    Hi, I am trying to get the below code snippet to compile. But it fails with: error C2665: 'boost::lambda::function_adaptor::apply' : none of the 8 overloads could convert all the argument types. Sepcifying the return type when calling bind does not help. Any idea what I am doing wrong? Thanks. #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> #include <string> #include <map> int main() { namespace bl = boost::lambda; typedef std::map<int, std::string> types; types keys_and_values; keys_and_values[ 0 ] = "zero"; keys_and_values[ 1 ] = "one"; keys_and_values[ 2 ] = "Two"; std::for_each( keys_and_values.begin(), keys_and_values.end(), std::cout << bl::constant("Value empty?: ") << std::boolalpha << bl::bind(&std::string::empty, bl::bind(&types::value_type::second, _1)) << "\n"); return 0; }

    Read the article

  • Conditional relation

    - by Lowgain
    I've got a model like this: Stem -id -etc And then I have Stemrelation -stem_id -related_stem_id -active I can get the related stems with the following relations class Stem < ActiveRecord::Base has_many :stemrelations has_many :related_stems, :through => :stemrelations end class Stemrelation < ActiveRecord::Base belongs_to :stem belongs_to :related_stem, :class_name => "Stem", :foreign_key => "related_stem_id" end But now I'd only like to get the active relations. I tried adding this to the Stem model: has_many :active_related, :through => :stemrelations, :source => :related_stem, :conditions => {:active => true} but this gives me an error becasue it tries to check the active flag on the stem model instead of the stemrelation. What do I change here? Thanks!

    Read the article

  • Conditional Styling In Silverlight?

    - by DeanMc
    Hi, While I'm fine with standard control styling in silverlight I have recently began using more dynamic methods of fetching data to be displayed in items controls. One of the controls I am reworking is a collection of links. The issue I am having is that each link is coloured differently when moused over. One red, one blue, one green, etc. Is there a way to style these items without sacrificing the dynamics of using an items control with a data template?

    Read the article

  • Firefox conditional comments CSS

    - by Kyle Sevenoaks
    Hi, the time has come to apply a targeted CSS hack to Firefox, first time for everything. Since Chrome, Safari and even IE are reading the thing perfectly fine, how would I apply the hack to this code? #cart2Salg { visibility: visible; position: absolute; left: 509px; top: 5px; z-index: 4; width: 66px; } Thanks

    Read the article

  • statemachine, conditional transitions

    - by astropanic
    I'm currently using Workflow. class Link < ActiveRecord::Base include Workflow workflow do state :new do event :process, :transitions_to => :checking #checking http_response_code & content_type end state :checking do event :process, :transitions_to => :fetching_links # fetching all links end state :fetching_links do event :process, :transitions_to => :checking #ready for next check end end end Now, I can do: l = Link.new l.process! l.process! l.process! l.process! # n times l.process! (in a loop, or cron job for example) But it can happens, some link will not respond or give me an invalid response durning the checking process. How I can conditionally switch to another state ? I mean something like this: class Link < ActiveRecord::Base include Workflow workflow do state :new do event :process, :transitions_to => :checking #checking http_response_code & content_type end state :checking do event :process, :transitions_to => :fetching_links # if all is fine event :process, :transitions_to => :failded # if something goes wrong end state :fetching_links do event :process, :transitions_to => :checking #ready for next check end end end

    Read the article

  • Problem with nested lambda expressions.

    - by Lehto
    Hey I'm trying to do a nested lambda expression like to following: textLocalizationTable.Where( z => z.SpokenLanguage.Any( x => x.FromCulture == "en-GB") ).ToList(); but i get the error: Member access 'System.String FromCulture' of 'DomainModel.Entities.SpokenLanguage' not legal on type 'System.Data.Linq.EntitySet`1[DomainModel.Entities.SpokenLanguage]. TextLocalization has this relation to spokenlanguage: [Association(OtherKey = "LocalizationID", ThisKey = "LocalizationID", Storage = "_SpokenLanguage")] private EntitySet<SpokenLanguage> _SpokenLanguage = new EntitySet<SpokenLanguage>(); public EntitySet<SpokenLanguage> SpokenLanguage { set { _SpokenLanguage = value; } get { return _SpokenLanguage; } } Any idea what is wrong?

    Read the article

< Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >