SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking 2 variables with the WHERE command in MySql

    This is my problem. I need to have the mysql query check for 2 variables. if they both are true, then that colum should be printed

    SELECT * FROM table WHERE row1 = '$p' && row2 = '0' ORDER BY id

    is this the right way to do it? cos it doesn't work. not with 1 '&' either
    chrome is a wrapper that combines a browser with spyware

  2. #2
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You tried:

    SELECT * FROM table WHERE row1 = '$p' AND row2 = '0' ORDER BY id


    Hope this helps,

    CaptainChainsaw

  3. #3
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    didn't work

    thanks anyways
    chrome is a wrapper that combines a browser with spyware

  4. #4
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM [table] WHERE [field1] = '$p' AND [field2] = 0 ORDER by [field3];

    of course you would replace the [] sections with your own table name and field names. Note that the 0 is not in quotes. This is because it is a number and by your query on the first post I am under the impression that your field2 is defined to hold numebers only. If it were a non-numeric field then you would enclose the 0 in single quotes. It is the same with variables. Any field defined to hold numerics only would be queried without quotes.

    If this is not returning what you want, then the problem is somewhere else other than the query.
    John

  5. #5
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, I sorted it out row2 didn't exist in the table

    thanks for the help
    chrome is a wrapper that combines a browser with spyware

  6. #6
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    John


Bookmarks

Posting Permissions

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