View Full Version : Need a push in the right direction

01-26-2008, 05:39 PM
I have a multi checkbox with 9 boxes they can select any three from the 9

This is one box of the 9
<input type="checkbox" name="subject[]" value="organic" onClick="CountChecks(this)">for Organic</font>

then submit to
$where = join($subjectChecked, ' = "y" OR ') . ' = "y"';

//Create Query
$query = "SELECT * FROM part WHERE $where AND WARDS = 'y' AND pet = 'y'";
$result = mysql_query($query) or die (mysql_error());
$num = mysql_numrows($result);

If in the database pet='n' it still brings it up as 'y'

it seem to find WARDS and 'y' and then ignore pet

any ideas on this please

01-27-2008, 04:08 PM
Try this modification:

$where = '('.join($subjectChecked, ' = "y" OR ') . ' = "y")';

That may fix your problem.

01-27-2008, 05:48 PM
I'm with MLSE, thinking that is the problem. Its an error with the logic flow - I believe that SQL runs logic from left to right instead of with the magnitude of the operator.
So, with SQL
1 OR 2 OR 3 AND 4 AND 5 is interpreted as:
(1 OR 2 OR (3 AND 4) AND 5) If i"m not mistaken.
This is different from PHP where the operators have a magnitude (and why you can choose between AND or && for example)
1 || 2 || 3 AND 4 && 5
Would be interpreted as:
(1 OR 2 OR 3) AND (4 AND 5)
For example. I can't find the logic flow on the php site (someone else confirm please), but if I'm not mistaken '||' operator has a higher precedence than the 'AND' operator, resulting in its evaluation first.
Hope thats the problem your are having, and hope that gives you a little insight as to what the problem is caused by.

01-27-2008, 07:50 PM
Thanks mlse
That piece of code seem to have done the trick

01-27-2008, 07:54 PM
Thank to you Fou-Lu
I think your logic is correct I will look into this a bit more when I have more time
But a Thank you for this thought