Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2011
    Location
    Swindon, England
    Posts
    124
    Thanks
    3
    Thanked 9 Times in 9 Posts

    PHP complex WHERE statement

    Hello,

    Below is the code i am talking about:

    PHP Code:
    $response mysql_query("SELECT * FROM  `tData`  
        WHERE word1 LIKE '%"
    .$q."%'
        OR conj LIKE '%"
    .$q."%' 
        OR word2 LIKE '%"
    .$q."%'
        OR username LIKE '%"
    .$q."%'
        OR lineID LIKE '%"
    .$q."%'
        ORDER BY `lineID` DESC LIMIT 0 , 10"
    ); 
    What i need is to make it so that the statement only selects the code with 'visible' (another field) set to 1... I have tried adding:

    AND visible = 1

    between

    OR lineID LIKE '%".$q."%'
    and
    ORDER BY `lineID` DESC LIMIT 0 , 10");

    however this has not worked.
    Last edited by LSCare; 07-05-2011 at 11:29 AM.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,294
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Assuming you want any of your like conditions to be satisfied only if visible is 1 then wrap the logic you already have in parenthesis then add the visible = 1 as shown below.

    PHP Code:
    $response mysql_query("SELECT * FROM  `tData`  
        WHERE (word1 LIKE '%"
    .$q."%'
        OR conj LIKE '%"
    .$q."%' 
        OR word2 LIKE '%"
    .$q."%'
        OR username LIKE '%"
    .$q."%'
        OR lineID LIKE '%"
    .$q."%')
        AND visible = 1
        ORDER BY `lineID` DESC LIMIT 0 , 10"
    ); 
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder
    Join Date
    Jun 2011
    Location
    Swindon, England
    Posts
    124
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Cheers for that... Wasn't aware I could use parenthesis in select statements.

    Sorted!


  •  

    Tags for this Thread

    Posting Permissions

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