www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] is this valid?

  1. #1
    Join Date
    Dec 2009
    Location
    City of Smiles
    Posts
    172

    resolved [RESOLVED] is this valid?

    Hello everyone.

    Can someone clarify me if this syntax is valid?

    PHP Code:
    $result mysql_query("SELECT * FROM users WHERE position_applied LIKE '%search%' AND age >=21 && <=30"); 
    I doubt my logic of having this kind of syntax, I'm planning to set a range in age.
    Last edited by kingdm; 01-11-2010 at 01:39 AM. Reason: retyped

  2. #2
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    AND age >=21 && <=30"
    must be changed to
    AND age >=21 AND age <=30"

  3. #3
    Join Date
    Dec 2009
    Location
    City of Smiles
    Posts
    172
    I see, so that's how it goes. Thanks once again Mr. Cool

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,639
    Quote Originally Posted by dk_zero-cool View Post
    AND age >=21 && <=30"
    must be changed to
    AND age >=21 AND age <=30"
    Actually, just as in PHP, MySQL supports both the AND and && operators (and the OR and || operators). However, it probably does make more sense to stick with one or the other in your SQL just for consistency. (Also, unlike PHP, in MySQL there is no difference in operator precedence between the two forms, so there is never a functional reason to use one over the other.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    #4 I Know. Even though I think AND and OR is was should be used for SQL (It just feels right since most people use it), it actually wasn't what I meant. She left out one of the "age" columns. She compared 30 with nothing. I just replaced the && with AND since that's what she started to use. It made more sense to use the same in both comparisons. But the missing column was the actual correction.

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,639
    Oops...I didn't even see that, just saw the different operators jumping out at me.

    I think you're correct that the "AND" and "OR" are more portable (ANSI standard?), but I'm not positive about that.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Dec 2009
    Location
    Denmark
    Posts
    240
    I think you're correct that the "AND" and "OR" are more portable (ANSI standard?), but I'm not positive about that.
    Hmm, don't know. I just think it is easier with some standards.
    Mine are:
    JavaScript, PHP = && and ||
    SQL = AND and OR

    (I also have an SQL rule that says that ALL SQL codes is written in upper-case.
    That way it's easier to tell the SQL apart from table names, column names etc.)

    If you start mixing it everywhere, it is going to be a hell reading your codes.

  8. #8
    Join Date
    Dec 2009
    Location
    City of Smiles
    Posts
    172
    Thanks for the both of you, I learn how to deal with my problem.

    Code:
    JavaScript, PHP = && and || 
    SQL = AND and OR
    I'll follow this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles