View Single Post
Old 03-07-2004, 13:23   #8
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: Help (again) ...

Quote:
Originally Posted by Richard M
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.
Cheers, that would be a bit tough to fit around my current queries though, what might be easier (if I had ANY clue how to do it) is to stop "furnishing" appearing in the URL string completely if they select "No Preference", must be some way of doing this with PHP in the actual form.
Bifta is offline   Reply With Quote