saravanataee Posted January 3, 2013 Share Posted January 3, 2013 (edited) Hi there, I am having the following triple drop down page and the code does works very well. But one small change i need to make.. the following code does shows three drop downs from which i can perform the action. Instead i want the three drop down's to be displayed inside a table as three different coloums. when i tried with <td>.<tr> it thrown me error. Any suggestion on how to put them in place inside a table but without changing functionality. <?php require "config.php"; ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Demo of Three Multiple drop down list box</title> <meta name="GENERATOR" content="Arachnophilia 4.0"> <meta name="FORMATTER" content="Arachnophilia 4.0"> <SCRIPT language=Javascript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='index.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='index.php?cat=' + val + '&cat3=' + val2 ; } </script> </head> <body> <table border="1"> <?php ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT itemname,item_id FROM item order by itemname"); ///////////// 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=$_GET['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 packingname,packing_id FROM packing where item_id=$cat order by packingname"); }else{$quer=mysql_query("SELECT DISTINCT packingname,packing_id FROM packing order by packingname"); } ////////// 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=$_GET['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 sizename FROM size where packing_id=$cat3 order by sizename"); }else{$quer3=mysql_query("SELECT DISTINCT sizename FROM size order by sizename"); } ////////// end of query for third subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='dd3ck.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['item_id']==@$cat){echo "<option selected value='$noticia2[item_id]'>$noticia2[itemname]</option>"."<BR>";} else{echo "<option value='$noticia2[item_id]'>$noticia2[itemname]</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['packing_id']==@$cat3){echo "<option selected value='$noticia[packing_id]'>$noticia[packingname]</option>"."<BR>";} else{echo "<option value='$noticia[packing_id]'>$noticia[packingname]</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[sizename]'>$noticia[sizename]</option>"; //echo "<input type='text' name='' value='$noticia[sizename]'/>"; } echo "</select>"; ////////////////// This will end the third drop down list /////////// ?> </table> </body> </html> Edited January 3, 2013 by saravanataee Quote Link to comment https://forums.phpfreaks.com/topic/272645-triple-drop-down-issue/ Share on other sites More sharing options...
Muddy_Funster Posted January 3, 2013 Share Posted January 3, 2013 what error did it throw? Quote Link to comment https://forums.phpfreaks.com/topic/272645-triple-drop-down-issue/#findComment-1402977 Share on other sites More sharing options...
saravanataee Posted January 3, 2013 Author Share Posted January 3, 2013 (edited) It doesnt throw error, but rather it dint populate me the drop downs properly. for eg if the click an item from 1st dropdown, 2nd dropdown automatically loads all values rather than a value associated with the selected item. Edited January 3, 2013 by saravanataee Quote Link to comment https://forums.phpfreaks.com/topic/272645-triple-drop-down-issue/#findComment-1402985 Share on other sites More sharing options...
Muddy_Funster Posted January 3, 2013 Share Posted January 3, 2013 you would wrap the <select> elementinside the <td> not the <option> element. simply echoing somting like this echo "<td><select name=\"name\"><?php //your option echo loop here ?> </select></td> should get your select boxes to appear in the table. Quote Link to comment https://forums.phpfreaks.com/topic/272645-triple-drop-down-issue/#findComment-1402989 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.