Jump to content

3 dependent drop-down list


Go to solution Solved by Yohanne,

Recommended Posts

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>";
?>

8157647655_b.jpg

Link to comment
https://forums.phpfreaks.com/topic/281154-3-dependent-drop-down-list/
Share on other sites

  • Solution

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'"); 
}

		
?>

1942707272_b.jpg 3108729937_b.jpg

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.