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