Page 1 of 1

query modification problem with checkboxes

Posted: Mon Nov 01, 2004 5:58 pm
by briwal222
I am running a restaurant search engine. Users can search by cuisine, city, etc. I would like to incorporate an advanced search where the users could modify the search by amenities, such as valet parking, waterfront view, etc. My current code for one search looks like this:

Code: Select all

<?php 
$db_name="";
$table_name="tblCuisine";
include'';
$db=mysql_select_db($db_name,$conn) or die(mysql_error());
$sql="SELECT cuisineID, cuisineName FROM $table_name order by cuisineName";
$result=mysql_query($sql,$conn)or die(mysql_error());

$num=mysql_num_rows($result);


if ($num < 1) &#123; 
print "<p><em>Sorry! No results.</em></p>"; 
&#125; else &#123; 

print " 
<form method="POST" ACTION="results_page.php"> 
<p><strong>Restaurant Cuisine:<br><br></strong> 
<select name="primaryCuisine">"; 


/* START WHILE LOOP */ 
while ($row = mysql_fetch_array($result)) &#123;
$cuisineID = $row&#1111;cuisineID]; 
$cuisineName = $row&#1111;cuisineName]; 
print"<br><option value="$cuisineID">$cuisineName</option>"; 
&#125; 
/* END WHILE LOOP */ 


print " 
<input type="hidden" name="searchValue" value="searchCuisine">
</select></p><br>
<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Select This Type">
</form>"; 

&#125; 

?>
I also have a tblRestaurantFeatures, and a tblFeatureType. tblRestaurantFeatures has restID, and featureID, while tblFeatureType has featureID and featureName. I am looking for the proper code to add in check boxes that the search would be modified with. Can anyone help me out on this??? :?

Posted: Mon Nov 01, 2004 6:41 pm
by kettle_drum
Add the check boxes with a name that has [] on the end, like:

Code: Select all

&lt;input type="checkbox" name="features&#1111;]" value="kids_play_area"&gt;
Then on the php processing side of the form you can use this like any array:

Code: Select all

foreach($_POST['features[]'] as $q){
   echo $q //add it to query or whatever
}