Page 1 of 1

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

Posted: Sun Jun 17, 2007 9:46 am
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 ";

Posted: Sun Jun 17, 2007 9:48 am
by superdezign
Have you tried grouping the ORs?

Posted: Sun Jun 17, 2007 9:52 am
by thiscatis
Hi,
Thanks for your quick reply.
Not quite following, don't think you are talking about the GROUP BY statement?

Posted: Sun Jun 17, 2007 9:54 am
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.

Posted: Sun Jun 17, 2007 9:59 am
by thiscatis
Thanks, both of you!
Solved.