Results 1 to 3 of 3

Thread: Collecting values from checkboxes to use in a category search

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default Collecting values from checkboxes to use in a category search

    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

    Code:
    " 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:

    Code:
     echo '<td width="253"><input type="checkbox" name="cats[]" value="'.$row['cat_id'].'">' .$row['category'].'</td>';
    Last edited by kuau; 08-12-2008 at 03:42 PM. Reason: code was wrong

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't know if you know about MySql's LIKE, NOTLIKE, and SOUNDSLIKE.
    Very helpful when your trying to make searches.
    Jeremy | jfein.net

  3. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •