Forum Moderators: coopster
<?php
//Open the connection
$conn = mysql_connect("*&*&*&*&","&*&*&**&*&€", "*&*&*&*&");
//Select the Database
mysql_select_db("*&*&*&*", $conn);
$total_records=0; // initialize
$results = $countphrase = null;
//
// Get a count of total records.
$sql= "select count(*) from `property`
WHERE `price` >= '".$_POST['minprice']."'
AND `price` <= '".$_POST['maxprice']."'
AND `bedrooms` >= '".$_POST['bedrooms']."'
AND `propertytype` = '".$_POST['propertytype']."'";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array($result);
//
$total_records = $row[0];
//
if ($total_records > 0) {
//Create the MySQL Command to retrieve the records
$sql= "SELECT * FROM `property`
WHERE `price` >= '".$_POST['minprice']."'
AND `price` <= '".$_POST['maxprice']."'
AND `bedrooms` >= '".$_POST['bedrooms']."'
AND `propertytype` = '".$_POST['propertytype']."'";
//
while ($array = mysql_fetch_array($result)) {
$propertyid = $array ['propertyid'];
$propertyaddress = $array['propertyadd1'].
$array['propertyadd2'].
$array['propertyadd3'].
$array['postcode'];
$propertytype = $array['propertytype'];
$bedrooms = $array['bedrooms'];
$price = $array['price'];
$description = $array['description'];
$results .= "
<tr>
<td class=\"right-align\">Price:£ </td><td> $price </td>
<td class=\"right-align\">Property Type: </td><td> $propertytype </td>
<td class=\"right-align\">Property Address: </td>
<td>
<a href=\"propertydetailsbox.php?propertyid=$propertyid\">$propertyaddress</a>
</td>
<td class=\"right-align\">Number of Bedrooms: </td><td> $bedrooms </td>
<td class=\"right-align\" valign=\"top\">Description: </td><td> $description </td>
</tr>
";
}
if ($results) {
if ($total_records==1) {
$countphrase = "<p>Your lucky day! We have $total_records record matching your search.</p>";
}
else {
$countphrase = "<p>There were $total_records matching records.</p>";
}
echo "
$countphrase
<table id=\"search-result\">$results</table>
";
}
else { echo "<p>Something wrong, $total_records found but no results.</p>"; }
} // end $total_records > 0;
else { echo "<p>No results were found with that search.</p>"; }
?>