Log in

View Full Version : Collecting values from checkboxes to use in a category search



kuau
08-12-2008, 03:33 AM
I am creating a search form and have most of it working, but for the section on searching by category I don't know how to retrieve the values from the selected checkboxes. Users can choose up to 39 possible categories but how do I create a where clause for an indeterminate number of selections? They might choose 10, or none. I thought I almost had it but realized my original plan would not work. I figure there must be a loop involved but don't know where to put it. This is as far as I can get so far... sorry, there's something about arrays and loops that I haven't quite grasped yet. Any help would be greatly appreciated. Thanks! e :)


" AND event_id IN (SELECT event_id FROM eventcat WHERE cat_id = x1 OR cat_id = x2 OR cat_id = x3 etc ";

This is the code in the search form that seems to correctly list the category checkboxes:


echo '<td width="253"><input type="checkbox" name="cats[]" value="'.$row['cat_id'].'">' .$row['category'].'</td>';

Nile
08-12-2008, 12:52 PM
I don't know if you know about MySql's LIKE, NOTLIKE, and SOUNDSLIKE (http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html).
Very helpful when your trying to make searches.

kuau
08-12-2008, 03:45 PM
Thanks, Nile. I never heard of SOUNDSLIKE but I do use LIKE "%$word%" in the part of the search that is on keywords. But the category ID's are integers and users can choose up to 39 of them so I don't know how to do it other than using a long list of "AND/OR cat_id = x AND/OR cat_id = x2". But I don't know how to collect the values from the checkboxes or how to concatenate them. Any ideas? I have to go to bed before it gets light. Bye for now. :)