outdoorxtreme1 Posted March 7, 2007 Share Posted March 7, 2007 Can some one take a look at my code. I am having problems getting the 3rd and 4th drop downs to work properly. What am I doing wrong? Also is there an easier way to do this using one table insead of multiple SQL tables? You can see my example here http://75.179.9.75/cars10.php <SCRIPT language=JavaScript> function reload1(form) { var val=form.type.options[form.type.options.selectedIndex].value; self.location='cars10.php?type=' + val ; } function reload2(form) { var val=form.type.options[form.type.options.selectedIndex].value; var val2=form.make.options[form.make.options.selectedIndex].value; self.location='cars10.php?type=' + val + '&make=' + val2 ; } function reload3(form) { var val=form.type.options[form.type.options.selectedIndex].value; var val2=form.make.options[form.make.options.selectedIndex].value; var val3=form.model.options[form.model.options.selectedIndex].value; self.location='cars10.php?type=' + val + '&make=' + val2 + '&model=' + val3 ; } </script> </head> <body> <? // ================================================================== // GETTING THE DATA FROM MYSQL TABLE FOR THE FIRST DROP DOWN LIST BOX // ================================================================== $quer1=mysql_query("SELECT DISTINCT vehicle_type,vehicle_type_id FROM vehicle_type order by vehicle_type"); // ========================================================== // END OF QUERY FOR THE FIRST vehicle_type DROP DOWN LIST BOX // ========================================================== // ============================================================================================= // FOR SECOND DROP DOWN LIST CHECK IF vehicle_type IS SELECTED ELSE DISPLAY ALL THE vehicle_make // ============================================================================================= $type=$HTTP_GET_VARS['type']; // This line is added to take care if the global variable is off if(isset($type) and strlen($type) > 0){ $quer2=mysql_query("SELECT DISTINCT vehicle_make,vehicle_make_id FROM vehicle_make where vehicle_type_id=$type order by vehicle_make"); }else{$quer2=mysql_query("SELECT DISTINCT vehicle_make,vehicle_make_id FROM vehicle_make order by vehicle_make"); } // =========================================================== // END OF QUERY FOR THE SECOND vehicle_make DROP DOWN LIST BOX // =========================================================== // ============================================================================================= // FOR THIRD DROP DOWN LIST CHECK IF vehicle_make IS SELECTED ELSE DISPLAY ALL THE vehicle_model // ============================================================================================= $make=$HTTP_GET_VARS['make']; // This line is added to take care if the global variable is off if(isset($make) and strlen($make) > 0){ $quer3=mysql_query("SELECT DISTINCT vehicle_model,vehicle_model_id FROM vehicle_model where vehicle_make_id=$make order by vehicle_model"); }else{$quer3=mysql_query("SELECT DISTINCT vehicle_model,vehicle_model_id FROM vehicle_model order by vehicle_model"); } // =========================================================== // END OF QUERY FOR THE THIRD vehicle_model DROP DOWN LIST BOX // =========================================================== // ============================================================================================= // FOR FOURTH DROP DOWN LIST CHECK IF vehicle_model IS SELECTED ELSE DISPLAY ALL THE vehicle_year // ============================================================================================= $model=$HTTP_GET_VARS['model']; // This line is added to take care if the global variable is off if(isset($model) and strlen($model) > 0){ $quer4=mysql_query("SELECT DISTINCT vehicle_year FROM vehicle_year where vehicle_year_id=$model order by vehicle_year"); }else{$quer4=mysql_query("SELECT DISTINCT vehicle_year FROM vehicle_year order by vehicle_year"); } // =========================================================== // END OF QUERY FOR THE FOURTH vehicle_year DROP DOWN LIST BOX // =========================================================== echo "<form method=post name=f1 action=''>"; // ============================= // START OF FIRST DROP DOWN LIST // ============================= echo "<select name='type' onchange=\"reload1(this.form)\"><option value=''>- Select -</option>"; while($noticia1 = mysql_fetch_array($quer1)) { if($noticia1['vehicle_type_id']==@$type){echo "<option selected value='$noticia1[vehicle_type_id]'>$noticia1[vehicle_type]</option>"."<BR>";} else{echo "<option value='$noticia1[vehicle_type_id]'>$noticia1[vehicle_type]</option>";} } echo "</select><br>"; // =============================== // END OF THE FIRST DROP DOWN LIST // =============================== // ============================== // START OF SECOND DROP DOWN LIST // ============================== echo "<select name='make' onchange=\"reload2(this.form)\"><option value=''>- Select -</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['vehicle_make_id']==@$make){echo "<option selected value='$noticia2[vehicle_make_id]'>$noticia2[vehicle_make]</option>"."<BR>";} else{echo "<option value='$noticia2[vehicle_make_id]'>$noticia2[vehicle_make]</option>";} } echo "</select><br>"; // ================================ // END OF THE SECOND DROP DOWN LIST // ================================ // ============================== // START OF THIRD DROP DOWN LIST // ============================== echo "<select name='model' onchange=\"reload3(this.form)\"><option value=''>- Select -</option>"; while($noticia3 = mysql_fetch_array($quer3)) { if($noticia3['vehicle_model_id']==@$model){echo "<option selected value='$noticia3[vehicle_model_id]'>$noticia3[vehicle_model]</option>"."<BR>";} else{echo "<option value='$noticia3[vehicle_model_id]'>$noticia3[vehicle_model]</option>";} } echo "</select><br>"; // ================================ // END OF THE THIRD DROP DOWN LIST // ================================ // ================================= // START OF THE FOURTH DROP DOWN LIST // ================================= echo "<select name='year' ><option value=''>- Select -</option>"; while($noticia4 = mysql_fetch_array($quer4)) { echo "<option value='$noticia4[vehicle_year]'>$noticia4[vehicle_year]</option>"; } echo "</select>"; // =============================== // END OF THE FOURTH DROP DOWN LIST // =============================== echo "</form>"; ?> Link to comment https://forums.phpfreaks.com/topic/41681-multi-drop-down-menu-population-problem/ Share on other sites More sharing options...
rofl90 Posted March 7, 2007 Share Posted March 7, 2007 You could tidy up most of ht code there are many consecutive echos in which all your echoing is html tags just have them seperate u rli dont need consecutive echos. Link to comment https://forums.phpfreaks.com/topic/41681-multi-drop-down-menu-population-problem/#findComment-201987 Share on other sites More sharing options...
outdoorxtreme1 Posted March 9, 2007 Author Share Posted March 9, 2007 I figured the problem I was having before. Now I am wondering how to associate part numbers and part descriptions for the selected make, model, year and have it display on the same page once the selection is made. I am not sure how to do this or if I have my 4th query right. Here is the new URL for the code I am working on http://75.179.9.75/cars25.php The only selections that work all the way thru right now are Acura, CL Series, 1997 - 2003 <SCRIPT language=JavaScript> function reload1(form) { var val=form.make.options[form.make.options.selectedIndex].value; self.location='cars25.php?make=' + val ; } function reload2(form) { var val=form.make.options[form.make.options.selectedIndex].value; var val1=form.model.options[form.model.options.selectedIndex].value; self.location='cars25.php?make=' + val +'&model=' + val1 ; } function reload3(form) { var val=form.make.options[form.make.options.selectedIndex].value; var val1=form.model.options[form.model.options.selectedIndex].value; var val2=form.year.options[form.year.options.selectedIndex].value; self.location='cars25.php?make=' + val +'&model=' + val1 +'&year=' + val2 ; } </script> <?php // Find available Makes $quer1=mysql_query("SELECT DISTINCT Make,v_make.Make_ID FROM v_make ORDER BY Make"); // Find models available for selected Type and Manufacturer $Make=$_GET['make']; if(isset($Make) and strlen($Make) > 0){ $quer2=mysql_query("SELECT Model,ID FROM v_model WHERE Make_ID = $Make ORDER BY Model"); }else{ $quer2=mysql_query("SELECT Model,ID FROM v_model WHERE 1 = 0"); } // Find Years available for model $Model=$_GET['model']; if(isset($Model) and strlen($Model) > 0){ $quer3=mysql_query("SELECT Year FROM v_year JOIN v_year_ref ON v_year.ID = v_year_ref.Year_ID AND v_year_ref.Model_ID = $Model ORDER BY Year"); }else{ $quer3=mysql_query("SELECT Year FROM v_year WHERE 1 = 0"); } // Find Part Number available for make, model and year selected $Year=$_GET['year']; if(isset($Year) and strlen($Year) > 0){ $quer4=mysql_query("SELECT Part_Number,Part_Description FROM v_year_ref WHERE Year_ID=$Year and Model_ID=$Model"); } else{ $quer4=mysql_query("SELECT Part_Number,Part_Description FROM v_year_ref WHERE 1=0"); } //Start form echo '<form method="post" name="f1" action="">'; // Choose Make echo '<select name="make" style="font-family: Tahoma; font-size: 10pt; height:28px;width:184px;" onchange="reload1(this.form)"><option value="">- Select Make -</option>'; while($noticia1 = mysql_fetch_array($quer1)) { if($noticia1['Make_ID']==$Make){ echo '<option selected value="' . $noticia1['Make_ID'] . '">' . $noticia1['Make'] . '</option>'.'<BR>'; }else{ echo '<option value="' . $noticia1['Make_ID'] . '">' . $noticia1['Make'] . '</option>'; } } echo '</select><br>'; // Choose Model echo '<select name="model" style="font-family: Tahoma; font-size: 10pt; height:28px;width:184px;" onchange="reload2(this.form)"><option value="">- Select Model -</option>'; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['ID']==$Model){ echo '<option selected value="' . $noticia2['ID'] . '">' . $noticia2['Model'] . '</option><BR>'; }else{ echo '<option value="' . $noticia2['ID'] . '">' . $noticia2['Model'] . '</option>'; } } echo '</select><br>'; // Choose Year echo '<select name="year" style="font-family: Tahoma; font-size: 10pt; height:28px;width:184px;" onchange="reload3(this.form)"><option value="">- Select Year -</option>'; while($noticia3 = mysql_fetch_array($quer3)) { echo '<option value="' . $noticia3['ID'] . '">' . $noticia3['Year'] . '</option><br>'; } echo '</select>'; // End form echo '</form>'; // Display Part Number For The Make, Model and Year Selected echo '<div>Part Number:</div>'; echo '<div>Part Description:</div>'; ?> Link to comment https://forums.phpfreaks.com/topic/41681-multi-drop-down-menu-population-problem/#findComment-203915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.