Quote:
|
Originally Posted by Bifta
Must have missed that heh, anyway it's now:
<select name="furnishing">
<option value="Furnished">Furnished</option>
<option value="Unfurnished">Unfurnished</option>
<option value="Part furnished">Part furnished</option>
<option value="Furnished to suit">Furnished to suit</option>
<option value="">No preference</option>
</select>
You see, there is no value in the database for "No Preference", so I want it to just somehow bypass the "furnishing" field somehow, I thought that furnishing= (with nothing after it) would show them all, but .. it doesn't  which is a bit odd, because if I set one of the other fields to say minbeds= (with nothing after it) it shows all the results. which is probably due to:
if ($minprice == "")
{
$minprice = 0;
}
in the results page. I just need to get something in there for furnishing (somehow)
|
No, what you'll need is this...
Use the HTML that I described in my post, you shouldn't use a blank value but the below code will still work anyway.
PHP Code:
<?php
if (isset($_GET['furnishing'])) {
$preference = $_GET['furnishing'];
$dbconnect = mysql_connect("localhost", "username", "password");
$dbname = "database name";
$tablename = "table name";
// If the "furnishing" field is empty (i.e. "") then do this:
if (empty($furnishing)) {
if (!$dbconnect) {
echo mysql_error();
exit;
}
if (!mysql_select_db($dbname)) {
echo mysql_error();
exit;
}
$sql = mysql_query("SELECT * FROM `$tablename`");
if (!$sql) {
echo mysql_error();
exit;
}
while ($sql_data = mysql_fetch_array($sql))
{
$price = $sql_data['price'];
// etc for each field you need
echo "Price: " . $price . "<br />";
}
mysql_free_result($sql);
mysql_close($dbconnect);
}
// If the "furnishing" field contains a value then do this:
else {
if (!$dbconnect) {
echo mysql_error();
exit;
}
if (!mysql_select_db($dbname)) {
echo mysql_error();
exit;
}
$sql = mysql_query("SELECT * FROM `$tablename` WHERE furnishing='$furnishing'");
if (!$sql) {
echo mysql_error();
exit;
}
while ($sql_data = mysql_fetch_array($sql))
{
$price = $sql_data['price'];
// etc for each field you need
echo "Price: " . $price . "<br />";
}
mysql_free_result($sql);
mysql_close($dbconnect);
}
}
?>
I haven't tested this but it should work.