Jump to content

3 Dynamic Dependent dropdowns


dhendler

Recommended Posts

This is driving me nuts.

 

I'm trying to create 3 dynamic dependent dropdowns that are all populated from 3 different fields on the same mysql table.

 

Their purpose is to sort a table of links to PDF files based on the criteria selected. (Select A + Select B + Select C + "Submit" = Displays list below)

 

I haven't even gotten to the display links part of it, I can't seem to get the dropdowns work the way I want.

 

Ideally, I would like them to be sticky and each have a static value of "all".

 

I've posted the code (so far) below, but let me know if you have any questions.

 

Thank you so much! Any help is appreciated  ;D

 

<?php  
$username="root";
$password="";
$database="proposals";
$server="localhost";
$ID = 0;

$con = mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");



$firstQry = mysql_query("select DISTINCT CATEGORY from  proposals") or die(mysql_error());        // table 1 
  
//////After getting the id from the table1 supply that posted id to get the resuls from the table2 ////////////// 
$secondQry = mysql_query("select DISTINCT AGENCY, CATEGORY from  proposals where CATEGORY = '$_POST[CAT]' ORDER BY AGENCY") or die(mysql_error());        // table 2

$thirdQry = mysql_query("select NAME, AGENCY, CATEGORY from proposals where CATEGORY = '$_POST[AGCY]' ORDER BY NAME") or die(mysql_error());        // table 3 

?> 
<form name="check" method="post"> 
    <!-- First DropDown starts here --> 
        <select name="CAT" onchange="this.form.submit()"> 
            <?php while($res = mysql_fetch_array($firstQry)){?> 
          
          <option  value="<?php echo $res["CATEGORY"]?>" <?php if (isset($_POST['CAT']) && $_POST['CAT'] == 'Highway') {
      echo 'selected="selected"';} ?>><?php echo $res["CATEGORY"]?></option> 
            <?php }unset($firstQry,$res);?> 
</select> 
    <!-- First DropDown ends here --> 
    <!-- Second DropDown starts here --> 
<?php if(isset($_POST['CAT'])){?> 
        <select name="AGCY" onchange="this.form.submit()"> 
            <?php while($row = mysql_fetch_array($secondQry)){?> 
          <option  value="<?php echo $row["AGENCY"]?>" <?php if (isset($_POST['AGCY']) && $_POST['AGCY'] == '"echo $row["AGENCY"]"') {
      echo 'selected="selected"';} ?>><?php echo $row["AGENCY"]?></option> 
            <?php } 
            }unset($secondQry,$row); ?> 
</select> 
    <!-- Second DropDown ends here --> 
    
        <!-- Third DropDown starts here --> 
<?php if(isset($_POST['AGCY'])){ ?> 
        <select name="NAME"> 
            <?php while($row2 = mysql_fetch_array($thirdQry)){ ?> 
          <option  value="<?php echo $row2["NAME"]?>"><?php echo $row2["NAME"]?></option> 
            <?php } 
            }
		unset($thirdQry,$row2);?> 
        </select> 
    <!-- Third DropDown ends here --> 

</form>

Link to comment
https://forums.phpfreaks.com/topic/128597-3-dynamic-dependent-dropdowns/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.