私は3つの動的ドロップリストを作成しています。2番目は最初の選択に基づいており、3番目は2番目の選択に基づいています.phpとmysqlを使用してデータとjavascriptを取得します
しかし、最初のリストで選択したものはすべて2番目と3番目に表示されるため、これは問題を解決する方法ではありません。
各テーブルで、選択した前にドロップリストの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>";
?>