Forum Moderators: coopster

Message Too Old, No Replies

check box problem

getting the correct value in the query string

         

swati

8:59 am on Dec 9, 2004 (gmt 0)

10+ Year Member



Hello,

I have 4 check boxes and beside each of them is a dropdown menu:- HOBBY,PETS,TRAVEL,MOVIES
User can select an option and check the box beside it to indicate that he wants a search to be performed using that option as well. Checkboxes are named filter[] so watever the user selects gets stored in the "filter" array. The user might have checked 1,2 or all of the boxes.From the values i ve to find their ids eg. idHobby for Hobby and idTravel for Travel.(i wud find it by "select idHobby from Hobby where name = 'the hobby value from array if it has been selected at all'") How do i even know if an option from hobby or travel was selected. How do I form the where clause of my query:
if the user selects only hobby and travel then it should be
where idHobby = xx and idTravel = yy

stuck!

macdave

2:31 pm on Dec 9, 2004 (gmt 0)

10+ Year Member



You can loop through the values of
$filter
and add to your query string as necessary:


$query = "SELECT * FROM foo WHERE 1=1 ";
foreach ($_GET['filter'] as $filter_value) {
$query .= "AND $filter_value = $_GET['appropriate_select_list_var'] ";
}