我正在创建三个动态下拉列表,第二个基于第一个的选择,第三个基于第二个的选择,使用 php 和 mysql 检索数据和 javascript
但这并没有发生如何解决问题,因为我在第一个列表中选择的所有内容都显示在第二个和第三个列表中。
在每个表中,我在选择完成之前都有下拉列表的 id 作为外键
谁能帮我 ????
代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register Page</title>
<link href="style/stylesheet.css" rel="stylesheet" type="text/css" />
<link href="style/imagesGallery.css"rel="stylesheet" type="text/css"/>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.governorate.options[form.governorate.options.selectedIndex].value;
self.location='register.php?governorate=' + val ;
}
function reload3(form)
{
var val=form.governorate.options[form.governorate.options.selectedIndex].value;
var val2=form.district.options[form.district.options.selectedIndex].value;
self.location='register.php?governorate=' + val + '&district=' + val2 ;
}
</script>
</head>
<body>
<?php
$governorate = "";
$district = "";
//$quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category");
$quer2=mysql_query("SELECT DISTINCT governorate_name,governorate_id FROM governorate order by governorate_name");
//$cat=$_GET['cat'];
$governorate=$_GET['governorate'];
var_dump($governorate);
if(isset($governorate) and strlen($governorate) > 0)
{
$quer=mysql_query("SELECT DISTINCT district_name,district_id FROM districts where governorate_id=$governorate order by district_name");
}
else
{
$quer=mysql_query("SELECT DISTINCT district_name,district_id FROM districts order by district_name");
}
$district=$_GET['district'];
if(isset($district) and strlen($district) > 0){
$quer3=mysql_query("SELECT DISTINCT village_name FROM village where district_id=$district order by village_name");
}
else
{
$quer3=mysql_query("SELECT DISTINCT village_name FROM village order by village_name");
}
echo "<select name='governorate' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2))
{
if($noticia2['governorate_id']==@$governorate)
{
echo "<option selected value='$noticia2[governorate_id]'>$noticia2[governorate_name]</option>"."<BR>";
}
else
{
echo "<option value='$noticia2[governorate_id]'>$noticia2[governorate_name]</option>";
}
}
echo "</select>";
echo "<select name='district' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer))
{
if($noticia['district_id']==@$district)
{
echo "<option selected value='$noticia[district_id]'>$noticia[district_name]</option>"."<BR>";
}
else
{
echo "<option value='$noticia[district_id]'>$noticia[district_name]</option>";
}
}
echo "</select>";
echo "<select name='village' ><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer3))
{
echo "<option value='$noticia[village_name]'>$noticia[village_name]</option>";
}
echo "</select>";
?>