cherubrock74 Posted April 23, 2009 Share Posted April 23, 2009 I've 3 drop down menu that are populated using a mysql db Based on the selection from the first menu, the second menu only displays certain options and so on up to the third. everything is working fine, except that now I would like to add more drop down menus so that a user can make more than one selection. The new menus would have to work the same way, but I need some help with the code. this is the working code I am using so far <?php require "config.php"; ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Demo of Three Multiple drop down list box from plus2net</title> <script language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='testing_drop.php?cat=' + val ; } function reload3(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; var val2=form.subcat.options[form.subcat.options.selectedIndex].value; self.location='testing_drop.php?cat=' + val + '&cat3=' + val2 ; } </script> </head> <?php ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// $cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id=$cat order by subcategory"); }else{$quer=mysql_query("SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"); } ////////// end of query for second subcategory drop down list box /////////////////////////// /////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3///// $cat3=$HTTP_GET_VARS['cat3']; // This line is added to take care if your global variable is off if(isset($cat3) and strlen($cat3) > 0){ $quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 where subcat_id=$cat3 order by subcat2"); }else{$quer3=mysql_query("SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"); } ////////// end of query for third subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='send.php'>"; ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";} else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { if($noticia['subcat_id']==@$cat3){echo "<option selected value='$noticia[subcat_id]'>$noticia[subcategory]</option>"."<BR>";} else{echo "<option value='$noticia[subcat_id]'>$noticia[subcategory]</option>";} } echo "</select>"; ////////////////// This will end the second drop down list /////////// ////////// Starting of third drop downlist ///////// echo "<select name='subcat3' ><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer3)) { echo "<option value='$noticia[subcat2]'>$noticia[subcat2]</option>"; } echo "</select>"; ////////////////// This will end the third drop down list /////////// echo "<input type=submit value='Submit the form data'></form>"; ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted April 23, 2009 Share Posted April 23, 2009 What does this have to do with mysql? Quote Link to comment Share on other sites More sharing options...
cherubrock74 Posted April 23, 2009 Author Share Posted April 23, 2009 Well I cant get to duplicate my drop down menus that are populated from the sql db... I hope someone can help me with the code...I imagine the php coding has to take into account that when creating 3 new drop down menus they should also be populated from the same mysql source... this is why I posted into mysql help...sorry if it was not appropriate any help? Quote Link to comment Share on other sites More sharing options...
revraz Posted April 23, 2009 Share Posted April 23, 2009 Should ask in the JS forums, since it's more JS functionality. Maybe a mod can move it for ya. Quote Link to comment Share on other sites More sharing options...
cherubrock74 Posted April 23, 2009 Author Share Posted April 23, 2009 Thanks RevRaz Mod can you move the thread or should I post again in JS as suggested? Quote Link to comment 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.