我有多个下拉列表框,其中包含来自数据库的数据,所以我想根据第一个的部分选择第二个下拉列表第一个
表有这三个字段
District_id(主键),district_name,Governate_id(外键)
第二个表有这三个字段
村庄_id(主键),村庄名,区ID(外键)
所以我希望用户首先选择地区框,然后根据选择的地区名称具有 id 我希望第二个框显示所有具有村庄.district_id = District.district_id 的村庄名称。谁能帮我??我正在选择独立于另一个的每个表,但我需要它基于第一个
代码块
function districtQuery(){
$distData = mysql_query("SELECT * FROM districts");
while($recorddist = mysql_fetch_array($distData)){
echo'<option value="' . $recorddist['district_name'] . '">' . $recorddist['district_name'] . '</option>';
}
}
// function for select by village
function villageQuery(){
//$villageData = mysql_query("SELECT * FROM village");
$villageData = mysql_query("SELECT village_name FROM village WHERE district_id = ('SELECT district_id FROM districts')") or die (mysql_error());
while($recordvillage = mysql_fetch_array($villageData)){
echo'<option value="' . $recordvillage['village_name'] . '">' . $recordvillage['village_name'] . '</option>';
}
}