ams53 Posted February 5, 2008 Share Posted February 5, 2008 I've got my dynamic drop down menu working. However, I need help get the results page linked properly. When the final drop down menu is selected, the form sends you to the correct page (i.e. product.php?product_id=), but the url parameter is always = 4. Basically the same page pops up no matter what is selected in the final drop down. Here is the code: <?php require_once('Connections/connUser.php'); //database connection /////////////////////////////////////////////////////////// mysql_select_db($database_connUser, $connUser); $query = "SELECT * FROM manufacturers ORDER BY manufacturers.manufacturer_name"; $result = @mysql_query($query) or die(mysql_error()); $rowMan = mysql_fetch_array($result); //////////////////////////////////////////////////////////// //////////////// Set Variables to Dummy if not Set////////// if (!isset($_POST['manufacturer'])) { $_POST['manufacturer'] = "undefine"; } if (!isset($_POST['type'])) { $_POST['type'] = "undefine"; } if (!isset($_POST['name'])) { $_POST['name'] = "undefine"; } if (!isset($_GET['model'])) { $_GET['model'] = "undefine"; } ////////////////////End Setting Dummies/////////////////////// $manufacturer = $_POST['manufacturer']; $type = $_POST['type']; $name = $_POST['name']; $product_id = $_GET['model']; if (isset($manufacturer)){ //////////////////////////////////////////////////////////// $query_man = sprintf("SELECT * FROM product_type WHERE manufacturer_id='$manufacturer' ORDER BY product_type.type"); $result_man = @mysql_query($query_man); $rowType = mysql_fetch_array($result_man); //////////////////////////////////////////////////////////// } if (isset($type)){ //////////////////////////////////////////////////////////// $query_type = sprintf("SELECT * FROM product_name WHERE type_id='$type' ORDER BY product_name.name"); $result_type = @mysql_query($query_type); $rowName = mysql_fetch_array($result_type); //////////////////////////////////////////////////////////// } if (isset($name)){ //////////////////////////////////////////////////////////// $query_name = sprintf("SELECT * FROM product WHERE name_id='$name' ORDER BY product.model_name"); $result_name = @mysql_query($query_name); $rowModel = mysql_fetch_array($result_name); //////////////////////////////////////////////////////////// } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <form id="form1" form name="form1" method="post" action="dropdown.php"> <select name="manufacturer" onChange="document.forms[0].submit()"> <option value="">Select Manufacturer</option> <?php do { ?> <option value="<?php echo $rowMan['manufacturer_id']; ?>"<?php if (!(strcmp($rowMan['manufacturer_id'], $manufacturer))) {echo "SELECTED";} ?>><?php echo $rowMan['manufacturer_name']; ?></option> <?php }while ($rowMan = mysql_fetch_array($result)); ?> </select> <select name="type" onChange="document.forms[0].submit()"> <option value="">Select Product Type</option> <?php do { ?> <option value="<?php echo $rowType['type_id']; ?>"<?php if (!(strcmp($rowType['type_id'], $type))) {echo "SELECTED";} ?>><?php echo $rowType['type']; ?></option> <?php }while ($rowType = mysql_fetch_array($result_man)); ?> </select> <select name="name" onChange="document.forms[0].submit()"> <option value="">Select Product Name</option> <?php do { ?> <option value="<?php echo $rowName['name_id']; ?>"<?php if (!(strcmp($rowName['name_id'], $name))) {echo "SELECTED";} ?>><?php echo $rowName['name']; ?></option> <?php }while ($rowName = mysql_fetch_array($result_type)); ?> </select> <select name="model" onChange="document.location.href='product.php?product_id=<?php echo $rowModel['product_id']?>'"> <option value="">Select Model Number</option> <?php do { ?> <option value="<?php echo $rowModel['product_id']; ?>"<?php if (!(strcmp($rowModel['product_id'], $product_id))) {echo "SELECTED";} ?>><?php echo $rowModel['model_name']; ?></option> <?php }while ($rowModel = mysql_fetch_array($result_name)); ?> </select> </form> </body> </html> Any Suggestions?? Quote Link to comment https://forums.phpfreaks.com/topic/89594-dynamic-drop-down-help/ Share on other sites More sharing options...
chronister Posted February 5, 2008 Share Posted February 5, 2008 did not look over the code real well as it is a bit challenging, but I would guess you are not using a loop to loop through the results that are populating the dropdown. I assume that 4 is the las ID it retrieves from the DB. Nate Quote Link to comment https://forums.phpfreaks.com/topic/89594-dynamic-drop-down-help/#findComment-459049 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.