Tom Canfarotta
Tom Canfarotta

Reputation: 773

PHP MySQL Search between with an "or" condition

I am attempting a search between two values with an or condition but can not seem to get this to work. Here is my search:

$search = mysql_query("SELECT * FROM `data` WHERE (`Required ACT` between ($act1) and ($act2) OR (`Required SAT` between ($sat1) and ($sat2))");

It works fine when alone but when the "or" is intorduced it break.

Thanks!

Upvotes: 0

Views: 125

Answers (1)

Jay Blanchard
Jay Blanchard

Reputation: 34416

By breaking the query over multiple lines and applying the logic you're looking for you'll see where your parentheses groups need to be:

SELECT * 
FROM `data` 
WHERE 
   (`Required ACT` BETWEEN ($act1) AND ($act2))
OR 
   (`Required SAT` BETWEEN ($sat1) AND ($sat2))

Upvotes: 2

Related Questions