Page 1 of 1

Dynamic selection menus...

Posted: Thu Aug 28, 2008 11:57 am
by mcgeownr
Hi, im reasonably new to PHP but ive got a php dynamic dropdown menu.

I have a primary selection list, when select, this fills the options for the sub category list. It works, and well. But i need 4 selection list, Primary Cat and Sub Cat, Secondary Cat and Sub Cat...i cant get it to work, it seem to duplicate all the data in both menus...heres the code for the two menus.

Code: Select all

 
<html>
    <head>
<SCRIPT language=JavaScript>
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dropdown.php?cat=' + val ;
}
</script>
    </head>
    <body>
 
<?php
 
include 'lib/config.php';
include 'lib/opendb.php';
 
$quer2=mysql_query("SELECT  category,cat_id FROM category order by Cat_id");
 
$cat=$_GET['cat'];
if(isset($cat) and strlen($cat) > 0)
{
$quer=mysql_query("SELECT  sub_category FROM sub_category where cat_id=$cat order by sub_category");
}
 
echo "<form method=post name=f1 action=''>";
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";}
else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";}
}
echo "</select>";
 
echo "<br>";
 
echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[sub_category]'>$noticia[sub_category]</option>";
}
echo "</select>";
echo "<br>";
echo "<input type=submit value=Submit>";
echo "</form>";
 
?>
</body>
</html>