Jump to content

3 dependent drop-down list


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
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.