0

I have this code:

$r=mysql_query("SELECT * FROM advertisements WHERE exposure!='0' AND `status`='2' AND clicks_left_micro>0 OR clicks_left_mini>0 OR clicks_left_standard>0 OR clicks_left_extended>0");

The above code, should ONLY get the 2 first rows, in my database. (Please check the pic below): http://i51.tinypic.com/dejiw.png

Why does it select all 3 rows, when I specifically say status="2"?

How can I fix this?

Thanks in advance.

3 Answers 3

4

Here is what you have:

SELECT * FROM advertisements 
WHERE exposure!='0' 
AND `status`='2' 
AND clicks_left_micro>0 
OR clicks_left_mini>0 
OR clicks_left_standard>0 
OR clicks_left_extended>0

But I think that this is what you actually wanted:

SELECT * FROM advertisements 
WHERE exposure!='0' 
AND `status`='2' 
AND (clicks_left_micro>0 
OR clicks_left_mini>0 
OR clicks_left_standard>0 
OR clicks_left_extended>0)
Sign up to request clarification or add additional context in comments.

Comments

0

You have to use parenthesis to respect boolean operators priority.

1 Comment

How can I include those in the query? Can you please provide an example?
0

Try encapsling the OR part in parentheses

AND clicks_left_micro>0 OR clicks_left_mini>0 OR 
clicks_left_standard>0 OR clicks_left_extended>0

changed to

AND (clicks_left_micro>0 OR clicks_left_mini>0 OR 
clicks_left_standard>0 OR clicks_left_extended>0)

should solve it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.