query modification problem with checkboxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
briwal222
Forum Newbie
Posts: 10
Joined: Fri Oct 29, 2004 9:47 am

query modification problem with checkboxes

Post 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??? :?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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
}
Post Reply