The DB is MySQL, I'll show you what I've got for a non filtering formula,(a this will have to do until I sort it code..)
// link to DB
//The usual connect
//Beginning
$area = $GET["area"];
$price = $GET["price"];
$bedrooms = $_GET["bedrooms"];
$sql = "SELECT * FROM tblprops"; // it's this bit I'm struggling with!!
$result = @ ($sql); // Run the query.
//End
echo '<table align="center" cellspacing="0" cellpadding="3" border="1" width="100%">
';
// Fetch and print all the records.
$bg = '#ffffff'; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bg = ($bg=='#ffffff' ? '#ffffff' : '#ffffff');
echo '<tr bgcolor="' . $bg . '" class="style1">
<td align="left" valign="middle"><img src="' . $row['image_link'] .'" width="175px" height="128px"></td>
<td align="left" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td align="left" valign="top" class="style5">Property ID: <b> ' . $row['propertyID'] . '</b> :: Priced From: <b>€ ' . $row['price'] . '</b> :: Type: <b> ' . $row['type'] . '</b> :: Name: <b>' . $row['name'] . '</b><br>
Area: <b> ' . $row['area'] . '</b> :: Bedrooms: <b> ' . $row['bedrooms'] . '</b> :: Bathrooms: <b> ' . $row['bathrooms'] . '</b><br>Pool:<b> ' . $row['pool'] . '</b>:: Garden:<b> ' . $row['garden'] . '</b>:: parking:<b> ' . $row['parking'] . '</b><br></td></tr>
<tr><td align="left" valign="top" class="style1">' . $row['description'] . '
</td>
</tr></table>
';
}
echo '</table>';
mysql_free_result ($result); // Free up the resources.
mysql_close(); // Close the database connection.
?>
I have tried:
<?php
$type=$GET[type];
$price_range=$GET[price];
$beds=$_GET[beds];
//if a plot no beds
if($type=="1" and $beds > 0)
{
$beds="0";
}
// link to data
$link_id = mysql_connect("$db_host","$db_user","$db_password");
if (mysql_select_db("$db_database", $link_id));
else die ("connection failed.") ;
$flag = 0;
$query_search="";
$message="You requested ";
if($type=="0")$message.= "any type of property ";
if($type !=="0")// if search is NOT for all a bit more needs to be added
{
if($type=="1")
{
$prop_type="Plot";
$message.="a plot ";
}
if($type=="2")
{
$prop_type="Apartment";
$message.="an apartment ";
}
if($type=="3")
{
$prop_type="Villa";
$message.="a villa ";
}
$query_search.= " WHERE prop_type = '$prop_type' ";
// now set a flag so we know that a WHERE has been addeed
$flag = 1;
}
if($price !=="0")//same again for price
{
if($price_range=="1")
{
$range=" < 100000 ";
$message.="priced less than 100,000 € ";
}
if($price_range=="2")
{
$range=" between 100000 and 200000";
$message.="priced between 100,000 € and 200,000 € ";
}
if($price_range=="3")
{
$range=" between 200000 and 300000";
$message.="priced between 200,000 € and 300,000 € ";
}
if($price_range=="4")
{
$range=" between 300000 and 400000";
$message.="priced between 300,000 € and 400,000 € ";
}
if($price_range=="5")
{
$range=" between 400000 and 500000";
$message.="priced between 400,000 € and 500,000 € ";
}
if($price_range=="6")
{
$range=" between 500000 and 600000";
$message.="priced between 500,000 € and 600,000 € ";
}
if($price_range=="7")
{
$range=" between 600000 and 700000";
$message.="priced between 600,000 € and 700,000 € ";
}
if($price_range=="8")
{
$range=" between 700000 and 800000";
$message.="priced between 700,000 € and 800,000 € ";
}
if($price_range=="9")
{
$range=" between 800000 and 900000";
$message.="priced between 800,000 € and 900,000 € ";
}
if($price_range=="10")
{
$range=" between 900000 and 1000000";
$message.="priced between 900,000 € and 1,000,000 € ";
}
if($price_range=="11")
{
$range=" > 1000000";
$message.="priced over 1,000,000 € ";
}
if($flag ==1)// we already added the WHERE
{
$query_search.= " AND price $range ";
}else{
// if this bit is actioned we need to add WHERE and set the flag
$query_search.= " WHERE price $range ";
$flag = 1;
}
}
if($beds !=="0")//same again for pattern
{
$message.="with at least $beds bedrooms ";
if($flag ==1)// we already added the WHERE
{
$query_search.= " AND beds >= $beds ";
}else{
$query_search.= " WHERE beds >= $beds ";
// as this is last dont need flag
}
}
(I did change it slightly to suit the DB I am using.