Be seen. Boost your question’s priority for more expert views and faster solutions
<input name="criteria[]" type="checkbox" id="Buffet" value="Buffet" />
<label for="Buffet">Buffet</label>
<?php
include "config.php";
if(isset($_POST['criteria']) && !empty($_POST['criteria'])){
foreach($_POST['criteria'] as $key=>$value){
// Runs mysql_real_escape_string() on every value encountered.
$clean_criteria = array_map('mysql_real_escape_string', $_REQUEST['criteria']);
// Convert the array into a string.
$criteria = implode("','", $clean_criteria);
if(!$rs=mysql_query("SELECT tblLocations.CityID, tblRestaurants.RestName, tblLocations.Street,
tblLocations.Phone, tblLocations.Price, tblLocations.Rating
FROM (tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID) INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID)
ON tblLocations.LocationID = tblLocDet.LocationID
WHERE tblLocations.CityID='16' AND tblDetails.DetailName IN ('$criteria')
ORDER BY tblRestaurants.RestName ASC"))
{
echo "Cannot parse query";
}
elseif(mysql_num_rows($rs) == 0) {
echo "No records found";
}
else {
echo "<table id=\"myTable\" table width=\"710\" class=\"beautifuldata\" align=\"Left\" cellspacing=\"0\">\n";
echo "<thead>\n<tr>";
echo "<th>PLACE</th>";
echo "<th>ADDRESS</th>";
echo "<th>PHONE</th>";
echo "<th>PRICE</th>";
echo "<th>RATING</th>";
echo "</tr>\n</thead>\n";
while($row = mysql_fetch_array($rs)) {
echo"<tr>
<td><strong><a href='$row[RestPage]'>$row[RestName]</a></strong></td>
<td>$row[Address]</td>
<td>$row[Phone]</td>
<td>$row[Price]</td>
<td>$row[Rating]</td>
</tr>\n";
}}
echo "</table><br />\n";
}}
?>
The link:
www.menuhead.net/Steelers/deep_search.php
In case you want to see first hand.
foreach($_POST['criteria'] as $value){
<?php
include "config.php";
if(!empty($_POST["criteria"])){
$arr = array();
foreach($_POST['criteria'] as $key=>$value) $arr[] = "'" . mysql_real_escape_string($value) . "'";
$criteria .= implode(",", $arr);
if(!$rs=mysql_query("SELECT tblLocations.CityID, tblRestaurants.RestName, tblLocations.Street,
tblLocations.Phone, tblLocations.Price, tblLocations.Rating
FROM (tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID) INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID)
ON tblLocations.LocationID = tblLocDet.LocationID
WHERE tblLocations.CityID='16' AND tblDetails.DetailName IN ('$criteria')
ORDER BY tblRestaurants.RestName ASC"))
{
echo "Cannot parse query";
}
elseif(mysql_num_rows($rs) == 0) {
echo "No records found";
}
else {
echo "<table id=\"myTable\" table width=\"710\" class=\"beautifuldata\" align=\"Left\" cellspacing=\"0\">\n";
echo "<thead>\n<tr>";
echo "<th>PLACE</th>";
echo "<th>ADDRESS</th>";
echo "<th>PHONE</th>";
echo "<th>PRICE</th>";
echo "<th>RATING</th>";
echo "</tr>\n</thead>\n";
while($row = mysql_fetch_array($rs)) {
echo"<tr>
<td><strong><a href='$row[RestPage]'>$row[RestName]</a></strong></td>
<td>$row[Address]</td>
<td>$row[Phone]</td>
<td>$row[Price]</td>
<td>$row[Rating]</td>
</tr>\n";
}
}
echo "</table><br />\n";
}
?>
<div id="result">
Cannot parse query</table><br />
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
.tblHead {
background-color: #002DD1;
color: white;
text-align: left;
}
</style>
</head>
<body>
<?php
if (isset ( $_POST ["btnSearch"] )) {
echo "<br>Selected Options are :<br>";
$checked = $_POST ["criteria"];
$criteria = "";
$separator = ", ";
for($i = 0; $i < count ( $checked ); $i ++) {
echo " " . $checked [$i] . "<br/>";
if ($i == count ( $checked ) - 1) {
$separator = "";
}
$criteria = $criteria . "'" . $checked [$i] . "'" . $separator;
}
echo "<br><br>";
echo $criteria . "<br><br>";
// Test DB Connection --- Modify it and test once
$con = mysql_connect ( "localhost", "username", "password" );
if (! $con) {
die ( 'Could not connect: ' . mysql_error () );
}
mysql_select_db ( "your_db_name", $con );
$mysqlQuery = "SELECT tblLocations.CityID, tblRestaurants.RestName, tblLocations.Street, ";
$mysqlQuery .= "tblLocations.Phone, tblLocations.Price, tblLocations.Rating ";
$mysqlQuery .= "FROM (tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID) ";
$mysqlQuery .= "INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ";
$mysqlQuery .= "ON tblLocations.LocationID = tblLocDet.LocationID ";
$mysqlQuery .= "WHERE tblLocations.CityID='16' AND tblDetails.DetailName IN (" . $criteria . ") ";
$mysqlQuery .= "ORDER BY tblRestaurants.RestName ASC ";
// Make sure you have formatted the MySQL query correctly especially in the inner join
// SELECT
// tblLocations.CityID,
// tblRestaurants.RestName,
// tblLocations.Street,
// tblLocations.Phone,
// tblLocations.Price,
// tblLocations.Rating
// FROM
// tblRestaurants
// INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID)
// INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID
// WHERE tblLocations.CityID='16'
// AND tblDetails.DetailName IN ('Buffet', 'Brunch', 'Cateringt', 'Great Views', 'Cheap Eats', 'Happy Hour', 'Delivery', 'Private Rooms(s)', 'Gastro-Pub',
// 'Lunch', 'On-Line Ordering', 'Waterfront', 'Hotel Dining', 'Pre / Post Theatre', 'Reservations', 'Wi-Fi', 'Live Entertainment',
// 'Text Ordering', 'Romantic', 'Sports Bar', 'Theme')
// ORDER BY tblRestaurants.RestName ASC
if (! $rs = mysql_query ( $mysqlQuery )) {
echo "Cannot parse query";
} elseif (mysql_num_rows ( $rs ) == 0) {
echo "No records found";
} else {
echo "<table id=\"myTable\" table width=\"710\" class=\"beautifuldata\" align=\"Left\" cellspacing=\"0\">\n";
echo "<thead>\n<tr>";
echo "<th>PLACE</th>";
echo "<th>ADDRESS</th>";
echo "<th>PHONE</th>";
echo "<th>PRICE</th>";
echo "<th>RATING</th>";
echo "</tr>\n</thead>\n";
while ( $row = mysql_fetch_array ( $rs ) ) {
echo "<tr><td><strong><a href='" . $row [RestPage] . "'>" . $row ['RestName'] . "</a></strong></td>";
echo "<td>" . $row ['Address'] . "</td>";
echo "<td>" . $row ['Phone'] . "</td>";
echo "<td>" . $row ['Price'] . "</td>";
echo "<td>" . $row ['Rating'] . "</td>";
echo "</tr>";
}
}
echo "</table><br />\n";
mysql_close ( $con );
}
?>
<form method="post" name="Critters" id="Critters">
<div align="left">
<table width="950" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th class="tblHead" width="11" scope="col"> </th>
<th class="tblHead" width="19" scope="col"> </th>
<th class="tblHead" width="195" scope="col">FEATURES</th>
<th class="tblHead" width="206" scope="col">MEAL PERIODS</th>
<th class="tblHead" width="215" scope="col">SERVICES</th>
<th class="tblHead" width="268" scope="col">TYPE OF PLACE</th>
<th class="tblHead" width="51" scope="col"> </th>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Buffet"
value="Buffet"> <label for="Buffet"> Buffet</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Breakfast"
value="Breakfast"> <label for="Breakfast"> Breakfast</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox" id="BYOB"
value="BYOB"> <label for="BYOB"> BYOB</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Bar Scene"
value="Bar Scene"> <label for="Bar Scene"> Bar Scene</label> </strong>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Fireplace"
value="Fireplace"> <label for="Fireplace"> Fireplace</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox" id="Brunch"
value="Brunch"> <label for="Brunch"> Brunch</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Catering"
value="Cateringt"> <label for="Catering"> Catering</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Business Dining" value="Business Dining"> <label
for="Business Dining"> Business Dining</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Great Views" value="Great Views"> <label for="Great Views">
Great Views</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Dinner"
value="Dinner"> <label for="Dinner"> Dinner</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Credit Cards" value="Credit Cards"> <label for="Credit Cards">
Credit Cards</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Cheap Eats"
value="Cheap Eats"> <label for="Cheap Eats"> Cheap Eats</label> </strong>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Outdoor Dining" value="Outdoor Dining"> <label
for="Outdoor Dining"> Outdoor Dining</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Happy Hour"
value="Happy Hour"> <label for="Happy Hour"> Happy Hour</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox" id="Delivery"
value="Delivery"> <label for="Delivery"> Delivery</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox" id="Diner"
value="Diner"> <label for="Diner"> Diner</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Private Rooms(s)" value="Private Rooms(s)"> <label
for="Private Room(s)"> Private Rooms(s)</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Late Night"
value="Late Night"> <label for="Late Night"> Late Night</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Food Truck / Cart" value="Food Truck / Cart"> <label
for="Food Truck / Cart"> Food Truck / Cart</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Gastro-Pub"
value="Gastro-Pub"> <label for="Gastro-Pub"> Gastro-Pub</label> </strong>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Raw Bar"
value="Raw Bar"> <label for="Raw Bar"> Raw Bar</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox" id="Lunch"
value="Lunch"> <label for="Lunch"> Lunch</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="On-Line Ordering" value="On-Line Ordering"> <label
for="On-line Ordering"> On-Line Ordering</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Group Dining" value="Group Dining"> <label for="Group Dining">
Group Dining</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Waterfront"
value="Waterfront"> <label for="Waterfront"> Waterfront</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Open 24 Hours" value="Open 24 Hours"> <label for="Open 24 Hours">
Open 24 Hours</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="On-Line Reservations" value="On-Line Reservations"> <label
for="On-line Reservations"> On-line Reservations</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Hotel Dining" value="Hotel Dining"> <label for="Hotel Dining">
Hotel Dining</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Wheelchair Access" value="Wheelchair Access"> <label
for="Wheelchair Access"> Wheelchair Access</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Pre / Post Theatre" value="Pre / Post Theatre"> <label
for="Pre / Post Theatre"> Pre / Post Theatre</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Reservations" value="Reservations"> <label for="Reservations">
Reservations</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Kid Friendly" value="Kid Friendly"> <label for="Kid Friendly">
Kid Friendly</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Wi-Fi"
value="Wi-Fi"> <label for="Wi-Fi"> Wi-Fi</label> </strong></td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Take-Out"
value="Take-Out"> <label for="Take-Out"> Take-Out</label> </strong>
</td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Live Entertainment" value="Live Entertainment"> <label
for="Live Entertainment"> Live Entertainment</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Text Ordering" value="Text Ordering"> <label for="Text Ordering">
Text Ordering</label> </strong></td>
<td><strong> <input name="criteria[]" type="checkbox"
id="People Watching" value="People Watching"> <label
for="People Watching"> People Watching</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Romantic"
value="Romantic"> <label for="Romantic"> Romantic</label> </strong>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Specials"
value="Specials"> <label for="Specials"> Specials</label> </strong>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Sports Bar"
value="Sports Bar"> <label for="Sports Bar"> Sports Bar</label> </strong>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox"
id="Tasting Menu" value="Tasting Menu"> <label for="Tasting Menu">
Tasting Menu</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Theme"
value="Theme"> <label for="Theme"> Theme</label> </strong></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong> <input name="criteria[]" type="checkbox" id="Trendy"
value="Trendy"> <label for="Trendy"> Trendy</label> </strong></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<p><input type="submit" name="btnSearch" id="btnSearch"
value=" SEARCH "></p>
</form>
</body>
</html>
Post me the result or error you got. Hope this will give you the right result.Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.