// This took me a while to suss out. But the following code will produce a drop down menu based on the fields in your database (obviously you will need to change some of the fields for your database) and will then forward you to a results page depending upon your slections. //The code for the results page is below as well // Please include a link back to this site http://www.stevesims.com/scripts.htm so that others can benefit from this script -------------------------------------------------------------------------------------------------- The Drop Down Menu code --------------------------------------------------------------------------------------------------
|
include "config.php";
if ($Submit) { // perform search only if a string was entered.
$db = mysql_connect ($Host, $User, $Password);
mysql_select_db ($DBName) or die ("Cannot connect to database");
// Add something like this
if ($fieldOne == 'All Areas') {
$fieldOne = "%"; // % = MySQL multi character wildcard
}
if ($fieldTwo == 'All Towns') {
$fieldTwo = "%";
}
if ($fieldThree == 'All Post Codes') {
$fieldThree = "%";
}
$srch="%".$Submit."%";
$query = "select * from houses WHERE areas LIKE '$fieldOne' AND towns LIKE '$fieldTwo' AND zip LIKE '$fieldThree' ";
$result = mysql_db_query("yourdatabasename", $query);
if ($result)
{
echo "Here are the results: "; echo "
Go back and type a string to search"; } ?> |