@oddz
Now that I am analyzing the code The query and this conditions are in the code already.
This is the query that will display all the restaurants based on users input and conditions
$strSQL = sprintf(
'SELECT
r.restaurants_id
,r.restaurantname
,r.image
,r.description
,r.address
,r.zip
,r.state
FROM
restaurants r
%s
%s
%s
LIMIT %d, %d'
,$boolIncludeZipCodes === true?'INNER JOIN restaurants_to_zip_codes rz ON r.restaurants_id = rz.restaurants_id ':''
,empty($arrSQLFilters)?'':' WHERE
'.implode(' OR ',$arrSQLFilters)
,$boolIncludeZipCodes === true?'GROUP BY r.restaurants_id':''
,$offset, $rowsperpage
);
$arrResult = mysql_query($strSQL) or die("Cannot execute:". mysql_error());
while($arrRow = mysql_fetch_assoc($arrResult)) {
$arrRestaurants[] = $arrRow;
}
this code here
'.implode(' OR ',$arrSQLFilters)
I think will do the same effect we are dicussing here, for the ones that doesn’t know the code the $arrSQLFilters contain the $strname, $strzipcode, $strstate, $arrOfferings and $arrFoodTypes
so above the final output is $arrRestaurants that variable will contain all the results we need.
As I have said the code I want to display as below won’t need a query then I can use the query above to display the fields based on the search?
fields I want to display.
$result = mysql_query($arrRestaurant);
$arrstate = mysql_fetch_array($result);
echo '<div class="information"><label>County:</label>
<div>'. $arrstate['county']. '</div>
<label>State:</label>
<div>'. $arrstate['state']. '</div>
<label>Zip Code:</label>
<div>'. $arrstate['zip']. '</div></div> <br><br>';
The filters goes are as below. As you can see below all the five form fields are inside the filters and used at the query above.
$arrSQLFilters = array();
// whether or not zip codes table needs to be included
$boolIncludeZipCodes = false;
// Zipcode filter
if(!empty($strZipCode)) {
$boolIncludeZipCodes = true;
$arrSQLFilters[] = sprintf(
"r.zip LIKE '%s'"
,"%$strZipCode%"
);
}
// State filter
if(!empty($strState)) {
$boolIncludeZipCodes = true;
$arrSQLFilters[] = sprintf(
"r.state = '%s'"
,$strState
);
}
// Restaurants name filter
if(!empty($strName)) {
$arrSQLFilters[] = sprintf(
"r.restaurantname LIKE '%s'"
,"%$strName%"
);
}
// Food types filter
if(!empty($arrFoodTypes) && !empty($arrFoodTypes[0])) {
$arrSQLFilters[] = sprintf(
'r.restaurants_id IN
(SELECT
restaurants_id
FROM
restaurants_restaurant_food_types
WHERE
restaurants_food_types_id IN (%s)
GROUP
BY
restaurants_id
HAVING
COUNT(*) = %u)'
,/*mysql_real_escape_string(*/ implode(',',$arrFoodTypes) /*)*/
,count($arrFoodTypes)
);
}
// Offerings Filter ie. eat-in, lunch, dinner, etc
if(!empty($arrOfferings)) {
$arrSQLFilters[] = sprintf(
'r.restaurants_id IN
(SELECT
restaurants_id
FROM
restaurants_to_restaurant_offering
WHERE
restaurants_offerings_id IN (%s)
GROUP
BY
restaurants_id
HAVING
COUNT(*) = %u)'
,/*mysql_real_escape_string(*/ implode(',',$arrOfferings) /*)*/
,count($arrOfferings) );
}
@PHPycho
They are working for the first three conditions but then when it comes to the conditional arrays
$where_sql .= " restaurant_id='$arrFoodTypes'";
$where_sql .= " restaurant_id='$arrOfferings'";
it won’t display the fields below, Which I am trying to display them whenever one of the five inputs are set $strname OR $strzipcode OR $strstate OR $arrOfferings OR $arrFoodTypes. Even $arrOfferings and $arrFoodTypes.