Forum Moderators: open
<form name="Selections" method="GET" action="<?=$PHP_SELF?>" >
Zipcode: <input type="text" name="Search">
<select name="Variety" size="1">
<option value="activities">Activities</option>
<option value="cafes and lounges">Cafes and Lounges</option>
<option value="restaurants">Hottest Restaurants</option>
<option value="fastfood">Quick Fastfood</option>
<option value="live music">Live Music</option>
<option value="local offers">Local Offers</option>
<option value="bucketlist">The Bucket List</option>
</select>
<input type="submit" name="submit" value="Search">
</form>
</div>
<div id="search_results">
<?php
include_once ('database_connection.php');
if(isset($_GET['Search'])){
$zipcode = trim($_GET['Search']) ;
$zipcode = mysqli_real_escape_string($dbc, $zipcode);
if(isset($_GET['Variety'])){
$variety = trim($_GET['Variety']) ;
$variety = mysqli_real_escape_string($dbc, $variety);
$query = "SELECT discounts.zipcode,discounts.type FROM discounts WHERE discounts.zipcode='%$zipcode%' AND discounts.type='%$variety%'";
//echo $query;
$result = mysqli_query($dbc,$query);
if($result){
if(mysqli_affected_rows($dbc)!=0){
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo '<div id="style"><p> <b> <small> Style: </small>'.$row['style'].
'</div></b></p> <div id="title"><small> Name: </small>'.$row['title'].
'</div><p> <div id="address"> <small> Address: </small>'.$row['address'].
'</div></b><hr>';
}
}else {
echo 'No Results for Zipcode "'.$_GET['Search'].'"';
}
}
}else {
echo 'Parameter Missing';
}
}
?>
mysqli_affected_rows($dbc)!=0
Gets the number of affected rows in a previous MySQL operation
// Put this somewhere near the top to quiet undefined
// variable errors on concatenation
$row_result=null;
//
$result = mysqli_query($dbc,$query) or die(mysqli_error()); // see note
if($result){
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
$row_result .= '<div id="style"><p> <b> <small> Style: </small>'.$row['style'].
'</div></b></p> <div id="title"><small> Name: </small>'.$row['title'].
'</div><p> <div id="address"> <small> Address: </small>'.$row['address'].
'</div></b><hr>';
}
if ($row_result) { echo $row_result; }
else { echo 'No Results for Zipcode "'.$_GET['Search'].'"'; }
}
The script will run, but it keeps displaying "no results for zipcode" when there is. Why is that?