Search code giving funny results
Posted: Fri Apr 11, 2008 2:32 pm
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I'm creating a search functionality where users can select the type of property they want to buy, the price range, the number of bedrooms and the area in which they want to search for a house.
My code seems to work as it shows up the desired results. However, it also shows ALL the properties stored in the database, which is not something I want it to do.
I am including the code for the search function below:
What the code is doing is that it first displays all the properties within the database and then it displays the real search results. It also displays the 'no records returned' error several times on the page. So where does the problem lie?
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I'm creating a search functionality where users can select the type of property they want to buy, the price range, the number of bedrooms and the area in which they want to search for a house.
My code seems to work as it shows up the desired results. However, it also shows ALL the properties stored in the database, which is not something I want it to do.
I am including the code for the search function below:
Code: Select all
<?
$proptype = $_POST['propertyType'];
$postcode = $_POST['postcode'];
$max = $_POST['propertyPriceMax'];
$min = $_POST['propertyPriceMin'];
$rooms = $_POST['propertyBedrooms'];
if(!$proptype == "House" && !$proptype == "Flat" && !$proptype == "Bungalow" && $rooms){
$query = mysql_query("SELECT * FROM property WHERE propertyBedrooms = '$rooms'");
if (mysql_num_rows($query) > 0){
while ($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
?>
<tr align = "LEFT">
<td>
<BR>
<BR>
<font face="Arial" color="#0B3A62">
<?
// Echo them out
echo "<a href=\"searchprocess.php?id=$row[propertyID]\">$row[propertyType]". ", £". $row[propertyPrice] ." in " . $row[propertyArea];
}
}
else{?>
<font face="Arial" color="#0B3A62">
<?
echo "There are no records returned for your search query."; }
}
?>
</a>
</font>
</BR>
</BR>
</td>
</tr>
<?
if(!$proptype == "House" && !$proptype == "Flat" && !$proptype == "Bungalow" && $max ){
$query = mysql_query("SELECT * FROM property WHERE propertyPrice<'$max'");
if (mysql_num_rows($query) > 0){
while ($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
?>
<tr align = "LEFT">
<td>
<BR>
<BR>
<font face="Arial" color="#0B3A62">
<?
// Echo them out
echo "<a href=\"searchprocess.php?id=$row[propertyID]\">$row[propertyType]". ", £". $row[propertyPrice] ." in " . $row[propertyArea];
}
}
else{?>
<font face="Arial" color="#0B3A62">
<?
echo "There are no records returned for your search query."; }
}
?>
</a>
</font>
</BR>
</BR>
</td>
</tr>
<?
if(!$proptype == "House" && !$proptype == "Flat" && !$proptype == "Bungalow" && $min){
$query = mysql_query("SELECT * FROM property WHERE propertyPrice>'$min'");
if (mysql_num_rows($query) > 0){
while ($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
?>
<tr align = "LEFT">
<td>
<BR>
<BR>
<font face="Arial" color="#0B3A62">
<?
// Echo them out
echo "<a href=\"searchprocess.php?id=$row[propertyID]\">$row[propertyType]". ", £". $row[propertyPrice] ." in " . $row[propertyArea];
}
}
else{?>
<font face="Arial" color="#0B3A62">
<?
echo "There are no records returned for your search query."; }
}
?>
</a>
</font>
</BR>
</BR>
</td>
</tr>
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: