CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Resolved PHP complex WHERE statement (http://www.codingforums.com/showthread.php?t=231151)

LSCare 07-05-2011 09:07 AM

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.

djm0219 07-05-2011 10:07 AM

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"
); 


LSCare 07-05-2011 11:28 AM

Cheers for that... Wasn't aware I could use parenthesis in select statements.

Sorted!


All times are GMT +1. The time now is 12:34 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.