Hey everyone.
I'm writing an AJAX filtering system. You can select options from checkboxes and my php script returns data relating to the options, dynamically.
I want to add a 'select all' option to the checkbox group. The way it works currently is that when the user clicks a checkbox, its ID number is added to an array, which is then turned into a comma separated string and sent to my script, where I use it like:
SELECT * FROM table WHERE fieldID IN ($string)
I tried giving my 'select all' box a value of * but doing something like:
WHERE IN (2, 3, *) or even WHERE IN (*) doesn't work - any ideas on getting this to work?
Matt
MySQL WHERE IN (*) - possible?
Moderator: General Moderators
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: MySQL WHERE IN (*) - possible?
I don't believe "WHERE IN (*)" works at all.
I recommend that you put a small If block in your PHP. Something like
This way if the select all is ticked you have no criteria for the query and the search returns all results. If you have anything else then it adds the WHERE IN clause to the SQL statement before execution.
I recommend that you put a small If block in your PHP. Something like
Code: Select all
$sql = "SELECT * FROM table";
if (!$selectAll){
$sql .= " WHERE fieldID IN (1,2,3)";
}
//execute $sql in your chosen db method
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: MySQL WHERE IN (*) - possible?
Fair enough - just wondered if there was a simpler way. I used your method - cheers.