我创建了三个动态下拉列表,第二个基于对第一个的选择,第三个基于对第二个的选择,使用php和mysql来检索数据和javascript。
但这并没有发生,如何解决问题,因为无论我在第一个列表中选择什么,所有内容都会显示在第二个和第三个列表中。
在每个表中,我将下拉列表的id作为外键放在选定的done之前
有人能帮我吗?
代码
<!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>";
?>发布于 2013-04-23 09:49:58
我运行了你做过的代码,它在我身上工作。我所做的唯一更改是创建表单元素。我必须创建一个表来使其发挥作用。我没有走遍整个村庄。当我让地区正常工作时,我停了下来。
<?php
$db = mysql_connect('127.0.0.1','root') or die('could not connect');
mysql_select_db('financial_system_local',$db);
?>
<!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>
<form>
<?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",$db);
echo mysql_error($db);
//$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",$db);
}
else
{
$quer=mysql_query("SELECT DISTINCT district_name,district_id FROM districts order by district_name",$db);
}
$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>";
?>
</form>https://stackoverflow.com/questions/16154766
复制相似问题