Forum Moderators: coopster

Message Too Old, No Replies

php

Help Please

         

Piper

8:19 pm on Jan 25, 2008 (gmt 0)

10+ Year Member



Can some help and tell me why this dont work properly
There can be no pets (n in the database) but it still registers as there is

$query = "SELECT * FROM parts WHERE $where AND WARDS = 'y' AND pets = 'y'";

mooger35

10:38 pm on Jan 25, 2008 (gmt 0)

10+ Year Member



Might be the $where variable. What is it set to?

Piper

8:43 am on Jan 26, 2008 (gmt 0)

10+ Year Member



Thanks for looking at it
I have a multi checkbox with 9 boxes they can select any three from the 9 .
This is one of the 9
<input type="checkbox" name="subject[]" value="organic" onClick="CountChecks(this)">for Organic</font>

then submit

$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);
?>

Thanks again

maxximus

10:58 am on Jan 26, 2008 (gmt 0)

10+ Year Member



Always helps if you echo/print_r anything you need to debug.

In this case you should start by echoing $query to see what statement is being used as the query.

By the looks of it your forming an array $subjectChecked from checkbox selections and then imploding it to a string with ' = "y" OR ' as the glue.

SELECT * FROM part WHERE foo = "y" OR boo = "y" AND WARDS = 'y' AND pet = 'y'

Try changing all quotes within statement to singles ie.

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

Also i'm a bit doubtful over the syntax with those 'ands' and 'ors'. Try running the statement through cmd line or phpmyadmin.

Piper

12:50 pm on Jan 26, 2008 (gmt 0)

10+ Year Member



Thanks
I wil try what you have suggested
and let you know the results.

Jim