3 dynamic dropdown boxes
Posted: Wed Jan 12, 2011 4:54 pm
I'm pretty new to PHP and I am having trouble with 3 dynamic dropdown boxes for selecting the heirarchy for a product database. I am using onchange to reload the form and passing the variables through the URL. All three dropdowns are populating correctly and the first 2 dropdowns are posting to the database, but the 3rd dropdown is not. I'm assuming there is an easy fix but I've been looking at it for hours and can't figure it out. Thanks for any help. Here is the code for populating the dropdown boxes...
and here is the code for the form...
Code: Select all
<?php
///////// Getting the data from Mysql table for first list box//////////
$catquer=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category");
///////////// End of query for first list box////////////
/////// for second drop down list - check if category is selected else display all the subcategory/////
$cat=$_GET['cat'];
if(isset($cat) and strlen($cat) > 0){
$subcatquer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id=$cat order by subcategory");
}else{$subcatquer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
/////// third drop down list /////
$subcat=$_GET['subcat'];
if(isset($subcat) and strlen($subcat) > 0){
$prodtypequer=mysql_query("SELECT DISTINCT product_type FROM product_type where subcat_id=$subcat order by product_type");
}else{$prodtypequer=mysql_query("SELECT DISTINCT product_type FROM product_type order by product_type"); }
////////// end of query for third subcategory drop down list box ///////////////////////////
Code: Select all
echo "<form method=post name=f1 action='item.php'>";
////////// Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select Category</option>";
while($row = mysql_fetch_array($catquer)) {
if($row['cat_id']==@$cat){echo "<option selected value='$row[cat_id]'>$row[category]</option>"."<BR>";}
else{echo "<option value='$row[cat_id]'>$row[category]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
?>
<br>
<br>
<?php
////////// Starting of second drop downlist /////////
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select Subcategory</option>";
while($row2 = mysql_fetch_array($subcatquer)) {
if($row2['subcat_id']==@$subcat){echo "<option selected value='$row2[subcat_id]'>$row2[subcategory]</option>"."<BR>";}
else{echo "<option value='$row2[subcat_id]'>$row2[subcategory]</option>";}
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
?>
<br>
<br>
<?php
////////// Starting of third drop downlist /////////
echo "<select name='product_type'><option value=''>Select Product Type</option>";
while($row3 = mysql_fetch_array($prodtypequer)) {
{echo "<option value='$row3[type_id]'>$row3[product_type]</option>";}
}
echo "</select>";
////////////////// This will end the third drop down list ///////////
?>