Filtering contents of selection menu from another menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
baudchaser
Forum Newbie
Posts: 1
Joined: Sat Aug 21, 2004 1:53 pm

Filtering contents of selection menu from another menu

Post by baudchaser »

I am making an insert form for a database with select menus that are populated from various tables. That is all working fine. Two of the tables are "Mfgs" and "Models". I have it working so that when a Manufacturer is selected from the pull-down jump menu, the MfgID is added to the URL. The Model menu then filters records by the MfgID in the URL so that only Models made by the selected Manufacturer are listed.

The problem I am having is that when a Manufacturer is selected and the page is reloaded (jump menu...even necessary?), the Manufacturer selection does not stick. How do you recommend I go about accomplishing this?

I have thought about having a static menu entry followed by the dynamic set of records pulled from the Manufacturers menu, but have the static entry use a variable that gets its value from the MfgID in the URL. The end result of this would be that when a Manufacturer is selected, it appears twice in the menu, once at the beginning of the menu for the static variable entry which is the default selection, and the second of course from the dynamic population from the database table. The code I have below accomplishes this except that the static variable is constantly set as "1". I can't figure out how to make it get its value from the MfgID in the URL.

Am I making this more complicated than it needs to be? Is there a more simple, or better way of accomplishing this? Bear in mind that my end goal is simply to have the Model menu filter its contents based on the selection from the Manufacturer menu so that both selections can be inserted into a database without having the Model menu be ridiculously long.

Code: Select all

$colname_rsModels = "1";
if (isset($_GET['MfgID'])) {
  $colname_rsModels = (get_magic_quotes_gpc()) ? $_GET['MfgID'] : addslashes($_GET['MfgID']);
}


<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+"?MfgID="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->


            <select name="menu1" onChange="MM_jumpMenu('parent',this,1)">
              <option value="<?php echo $row_rsMfgs['MfgID']?>" selected><?php echo $row_rsMfgs['Manufacturer']?></option>
              <?php
do {  
?>
              <option value="<?php echo $row_rsMfgs['MfgID']?>"><?php echo $row_rsMfgs['Manufacturer']?></option>
              <?php
} while ($row_rsMfgs = mysql_fetch_assoc($rsMfgs));
  $rows = mysql_num_rows($rsMfgs);
  if($rows > 0) {
      mysql_data_seek($rsMfgs, 0);
	  $row_rsMfgs = mysql_fetch_assoc($rsMfgs);
  }
?>
            </select>


          <select name="selectModel">
            <option value="" <?php if (!(strcmp("", $row_rsModels['Model']))) {echo "SELECTED";} ?>></option>
            <?php
do {  
?>
            <option value="<?php echo $row_rsModels['ModelID']?>"<?php if (!(strcmp($row_rsModels['ModelID'], $row_rsModels['Model']))) {echo "SELECTED";} ?>><?php echo $row_rsModels['Model']?></option>
            <?php
} while ($row_rsModels = mysql_fetch_assoc($rsModels));
  $rows = mysql_num_rows($rsModels);
  if($rows > 0) {
      mysql_data_seek($rsModels, 0);
	  $row_rsModels = mysql_fetch_assoc($rsModels);
  }
?>
Post Reply