Jump to content

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


tooNight

Recommended Posts

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>[/code]

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>";
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.