PHP Dynamic Drop Down Menus, page displays diff data depending on dropdown selected.

Associate
Joined
19 Mar 2005
Posts
569
Just wondering if anyone can help me, what I am trying to do is to here. I currently have two drop down menus the first one with countries and then the second one changes depending on which country is selected to display counties. This works fine, now what I want to do is have it so when it county is selected it shows all the squash clubs that are in that county below the drop downs.

Would be great if someone could help me out.

Javascript

Code:
<SCRIPT language=JavaScript>
function reload(form){
var val=form.country.options[form.country.options.selectedIndex].value;
self.location='<?php echo $_SERVER['PHP_SELF']; ?>?country=' + val ;
}
</script>

Php
Code:
<?php 
		$quer2=mysql_query("SELECT countries.countryID, countries.countryName FROM countries") or die(mysql_error());
		if(isset($country) and strlen($country) > 0){
	$quer=mysql_query("SELECT countyID, countyName FROM counties WHERE cCountryID=$country");
	}else{$quer=mysql_query("SELECT countyName, countyID FROM counties");}




echo "<form method=post name=f1 action=''>";
/// Add your form processing page address to action in above line. Example action=dd-check.php////
////////// Starting of first drop downlist /////////
echo "<select name='country' onchange=\"reload(this.form)\">Select one";
while($row2 = mysql_fetch_array($quer2)) {
if($row2['countryID']==$country){echo "<option selected value='$row2[countryID]'>$row2[countryName]"."
";}
else{echo "<option value='$row2[countryID]'>$row2[countryName]";}
}
echo "</select>";

////////////////// This will end the first drop down list ///////////

////////// Starting of second drop downlist /////////
echo "<select name='county'>Select one";
while($row = mysql_fetch_array($quer)) {
echo "<option value='$row[countyID]'>$row[countyName]";

}
echo "</select>";
////////////////// This will end the second drop down list ///////////
echo "</form>";


//My Attempt at fetching club where cCounty & cCountry both in club table are the same as $county and $country.
$p2=mysql_query("SELECT club.clubID, club.cClubName FROM club WHERE cCounty = $countyID AND cCountry = $country") or die(mysql_error());
echo "<ol>";
while($row=mysql_fetch_assoc($p2)) {


echo "<li><a href=\"clubDetails.php?clubID=$row[clubID]\">$row[cClubName]</a></li>\r\n";

}
echo "</ol>";
?>
 
Back
Top Bottom