I have put together the code below to dynamically populate three drop down menus from a mysql database. I now need to create a results page. I am having a problem though due to the number of combinations available that the user may select.
Can someone show me how to create a results page that would cover all available options.
Many thanks.
My code:
<?php
include "config.php";
$db = mysql_connect ($Host, $User, $Password);
mysql_select_db ($DBName) or die ("Cannot connect to database");
/ We have now connected, unless you got an error message /
?>
<?php
$query_Areas = "SELECT DISTINCT areas FROM houses ORDER by areas";
$Areas = mysql_query($query_Areas) or die(mysql_error());
$row_Areas = mysql_fetch_assoc($Areas);
?>
<?php
$query_Towns = "SELECT DISTINCT towns FROM houses ORDER by towns";
$Towns = mysql_query($query_Towns) or die(mysql_error());
$row_Towns = mysql_fetch_assoc($Towns);
?>
<?php
$query_zip = "SELECT DISTINCT zip FROM houses ORDER by zip";
$zip = mysql_query($query_zip) or die(mysql_error());
$row_zip = mysql_fetch_assoc($zip);
?>
<body>
<form name="form" method="post" action="results.php">
<p>
<select name="field_1">
<option value="allareas">All areas</option>
<?php
do {
?>
<option value="<?php echo $row_Areas['areas']?>"><?php echo $row_Areas['areas']?></option>
<?php
} while ($row_Areas = mysql_fetch_assoc($Areas));
?>
</select>
</p>
<p>
<select name="field_2">
<option value="alltowns">All Towns</option>
<?php
do {
?>
<option value="<?php echo $row_Towns['towns']?>"><?php echo $row_Towns['towns']?></option>
<?php
} while ($row_Towns = mysql_fetch_assoc($Towns));
?>
</select>
<?php
mysql_free_result($Towns);
?>
</p>
<p>
<select name="field_3">
<option value="allzips">All Post Codes</option>
<?php
do {
?>
<option value="<?php echo $row_['zip']?>"><?php echo $row_zip['zip']?></option>
<?php
} while ($row_zip = mysql_fetch_assoc($zip));
?>
</select>
<?php
mysql_free_result($zip);
?>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
<?php
mysql_free_result($Areas);
?>
This displays a drop down for areas, towns and zip. I would like to give the user the option of selecting any field from the drop downs including an 'all' option where for example all areas would be selected...