Yohanne Posted August 14, 2013 Share Posted August 14, 2013 Hi coders. i achieve 2 dependent drop-down list in more than 5hours of working, and in my case i need 3 dependent drop-down to achieve completely. i use only one table and no querying happen at all. like image below, i get lost to manage in the last part. please help to do correct my code since i get lost on how to add another dependent dropdown in item name part. this code below is working good in just 2 dependent drop-down <SCRIPT language=JavaScript> function reload(form) { var val=form.category_name.options[form.category_name.options.selectedIndex].value; self.location='addrequest.php?category_name=' + val ; } </script> <?php require "../protected/db/db.php"; $sdb = new db(); @$category_name = $_GET['category_name']; if(strlen($category_name) > 0 and is_numeric($category_name)) { echo "Query Error"; exit; } $quer2 = mysql_query("SELECT DISTINCT category_name FROM pro_item"); if(isset($category_name) and strlen($category_name) > 0) { $quer = mysql_query("SELECT DISTINCT supplier_name, category_name FROM pro_item WHERE category_name = '$category_name'"); $quer3 = mysql_query("SELECT DISTINCT item_name, category_name FROM pro_item WHERE category_name = '$category_name'"); } else { $quer=mysql_query("SELECT DISTINCT item_name, supplier_name, category_name FROM pro_item"); } ?> ***CATEGORY*** <?php echo "<select name='category_name' onchange=\"reload(this.form)\"><option>Select Category</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['category_name']===@$category_name) { echo "<option selected value='$noticia2[category_name]'>$noticia2[category_name]</option>"."<BR>"; } else { echo "<option value='$noticia2[category_name]'>$noticia2[category_name]</option>"; } } echo "</select>"; ?> ***SUPPLIER*** <?php echo "<select name='subcat'> <option value=''>Select Name</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[supplier_name]'>$noticia[supplier_name]</option>"; } echo "</select>"; ?> ***ITEM NAME*** <?php echo "<select name='subcat'> <option value=''>Select Name</option>"; while($noticia = mysql_fetch_array($quer3)) { echo "<option value='$noticia[item_name]'>$noticia[item_name]</option>"; echo "</select>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/281154-3-dependent-drop-down-list/ Share on other sites More sharing options...
fastsol Posted August 14, 2013 Share Posted August 14, 2013 Check out this tutorial I have http://amecms.com/article/Building-Chained-Select-Boxes-with-Jquery-and-PHP Quote Link to comment https://forums.phpfreaks.com/topic/281154-3-dependent-drop-down-list/#findComment-1444981 Share on other sites More sharing options...
Yohanne Posted August 15, 2013 Author Share Posted August 15, 2013 Hi coders, Do you have any other tutorials? i know i am near to what i want. my problem in here is how to re-reload in supplier dropdown part to get all list under in supplier. please coders help me. Quote Link to comment https://forums.phpfreaks.com/topic/281154-3-dependent-drop-down-list/#findComment-1445087 Share on other sites More sharing options...
Solution Yohanne Posted August 15, 2013 Author Solution Share Posted August 15, 2013 solve: and i just to share to you all my solution. hope it help to others <SCRIPT language=JavaScript> function reload(form) { var val=form.category_name.options[form.category_name.options.selectedIndex].value; self.location='addrequest.php?category_name=' + val ; } function reloadtwo(form) { var val=form.category_name.options[form.category_name.options.selectedIndex].value; var val1=form.supplier_name.options[form.supplier_name.options.selectedIndex].value; self.location='addrequest.php?category_name=' + val + '&supplier_name=' + val1 ; } </script> <?php @$category_name = $_GET['category_name']; @$supplier_name = $_GET['supplier_name']; if(strlen($category_name) > 0 and is_numeric($category_name)) { echo "Query Error"; exit; } elseif(strlen($supplier_name) > 0 and is_numeric($supplier_name)) { echo "Query Error"; exit; } $quer2 = mysql_query("SELECT DISTINCT category_name FROM pro_item"); if(isset($category_name) and strlen($category_name) > 0) { $quer = mysql_query("SELECT DISTINCT supplier_name, category_name FROM pro_item WHERE category_name = '$category_name'"); } $quer3 = mysql_query("SELECT DISTINCT supplier_name, category_name FROM pro_item WHERE category_name = '$category_name'"); if(isset($supplier_name) and strlen($supplier_name) > 0) { $quer33 = mysql_query("SELECT DISTINCT item_name,supplier_name,category_name FROM pro_item WHERE category_name = '$category_name' and supplier_name = '$supplier_name'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/281154-3-dependent-drop-down-list/#findComment-1445088 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.