hi....i'm stuck in populate data inside the drop down list. the problem is, when i already success in populating data from db in 1st drop down list, i cannot carry the value. second drop down list data will depends on this value in order to populate data from array into it. same list of array for all the 1st data selected. the third drop down list will display different array for different data selected from the second drop down list. this the my code:
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
//////// End of connecting to database ////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Multiple drop down list box from plus2net</title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd.php?cat=' + val ;
}
</script>
</head>
<body>
<?php
please help me....
@$cat=$_GET; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not.
echo "Data Error";
exit;
}
$query="SELECT DISTINCT Location FROM serial order by Location";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
echo "<form method=post name=f1 action=''>";
$result = mysql_query ($query);
echo "<select name=cat value=''><Option value=''>Please Select Location</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[Location]>$nt[Location]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
echo "<select name=section value=''><Option value=''>Please Select Section</option>";
if(isset($cat) and strlen($cat) > 0){
echo "<option value='METRO'>METRO</option>";
echo "<option value='E-SIDE'>E-SIDE</option>";
echo "<option value='D-SIDE'>D-SIDE</option>";
}
echo "</select>";// Closing of list box
echo "</form>";
/*else{
$quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory order by subcategory");
}*/
?>
</body>
</html>