hi friends,
This is my code but it not working properly.pls tell the solution
<?php
mysql_connect("localhost","root","");
mysql_select_db("samples");
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title></title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='drop3.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='drop3.php?cat1=' + val + '&cat3=' + val2 ;
}
</script>
</head>
<body>
<?php
// Getting the data from Mysql table for first list box
$query1=mysql_query("SELECT DISTINCT category,cat_id FROM table1 order by category");
$cat=$_REQUEST['cat'];
echo $cat;
if(isset($cat) and strlen($cat) > 0)
{
$query2=mysql_query("SELECT DISTINCT subcategory,sub_id FROM table1 where cat_id=$cat order by subcategory");
}
else
{
$query2=mysql_query("SELECT DISTINCT subcategory,sub_id FROM table1 order by subcategory");
}
// end of query for second subcategory drop down list box ///////////////////////////
$cat3=$_REQUEST['cat1'];
echo $cat3;
if(isset($cat3) and strlen($cat3) > 0)
{
$query3=mysql_query("SELECT DISTINCT `titles` FROM `table1` WHERE `sub_id`= $cat3 order by titles");
}
else
{
$query3=mysql_query("SELECT DISTINCT titles FROM table1 order by titles");
}
// end of query for third subcategory drop down list box
echo "<form method=post name=f1 action='drop33.php'>";
// Starting of first drop downlist
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($fetch1 = mysql_fetch_array($query1))
{
if($fetch1['cat_id']==@$cat)
{
echo "<option selected value='$fetch1[cat_id]'>$fetch1[category]</option>"."<BR>";
}
else
{
echo "<option value='$fetch1[cat_id]'>$fetch1[category]</option>";
}
}
echo "</select>";
// Starting of second drop downlist
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($fetch2 = mysql_fetch_array($query2))
{
if($fetch2['cat_id']==@$cat3)
{
echo "<option selected value='$fetch2[sub_id]'>$fetch2[subcategory]</option>"."<BR>";
}
else
{
echo "<option value='$fetch2[sub_id]'>$fetch2[subcategory]</option>";
}
}
echo "</select>";
//Starting of third drop downlist
echo "<select name='subcat3' ><option value=''>Select one</option>";
while($fetch3 = mysql_fetch_array($query3))
{
echo "<option value='$fetch3[titles]'>$fetch3[titles]</option>";
}
echo "</select>";
echo "<input type=submit value='Submit the form data'></form>";
?>
</body>
</html>
database table:
id cat_id category sub_id
1 1 Websites/IT and Softwares acc1
2 1 Websites/IT and Softwares black
3 1 Websites/IT and Softwares black
4 2 Writing and Content act
subcategory title
accessdb linkdatabase
BlackBerry Advertising
BlackBerry googlecalender
accademic good english writer
writing
AccademicWriting
good english writer