[SOLVED] PHP + SQL: Not getting the rows I want

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

[SOLVED] PHP + SQL: Not getting the rows I want

Post by thiscatis »

Hi!

I need to get all the rows where a user id comes up in either s_user1, s_user2, s_user3 and the user has a video. But it shows up all the rows, either it has a video or not.
If I leave only the s_vids= 'Yes' it works. but with the s_user OR ... it doesn't..

Code: Select all

$SQL = " SELECT * FROM shoots WHERE s_user1= '$m_id' OR s_user2 ='$m_id' OR s_user3 ='$m_id'  AND s_vids = 'Yes' AND s_date <= $today  ORDER BY s_id DESC ";
Last edited by thiscatis on Sun Jun 17, 2007 9:59 am, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Have you tried grouping the ORs?
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

Hi,
Thanks for your quick reply.
Not quite following, don't think you are talking about the GROUP BY statement?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

superdezign is referring to adding parentheses around the ORs as they have the same precedence as the ANDs making the evaluation not follow what you want.
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

Thanks, both of you!
Solved.
Post Reply