Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-05-2011, 09:07 AM   PM User | #1
LSCare
Regular Coder

 
Join Date: Jun 2011
Location: Swindon, England
Posts: 124
Thanks: 3
Thanked 9 Times in 9 Posts
LSCare is an unknown quantity at this point
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..
LSCare is offline   Reply With Quote
Old 07-05-2011, 10:07 AM   PM User | #2
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Old 07-05-2011, 11:28 AM   PM User | #3
LSCare
Regular Coder

 
Join Date: Jun 2011
Location: Swindon, England
Posts: 124
Thanks: 3
Thanked 9 Times in 9 Posts
LSCare is an unknown quantity at this point
Cheers for that... Wasn't aware I could use parenthesis in select statements.

Sorted!
LSCare is offline   Reply With Quote
Reply

Bookmarks

Tags
php, query, select, sql

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:21 AM.


Advertisement
Log in to turn off these ads.