我正在使用PHP和Postgresql / PostGIS数据库。我的数据库模式是这样的。
我使用以下代码
<?php
$con = pg_connect("Connection Parameter");
if (!$con)
{
die("Could not connect: " . pg_last_error());
}
$divquery = "SELECT DISTINCT divname FROM union_bgd
ORDER BY divname";
$distquery = "SELECT DISTINCT distname FROM union_bgd
ORDER BY distname";
$resultDiv = pg_query($con, $divquery);
$resultDist = pg_query($con, $distquery);
?>
Division
<select id="division" name="division" onclick = "">
<option value="" selected="selected">Select a Division</option>
<?php
while($dd1 = pg_fetch_array( $resultDiv ))
{
echo '<option value= "' . $dd1['divname'] . '">' . $dd1['divname'] . '</option>';
}
?>
</select></br>
District
<select id="district" name="district" onclick = "">
<option value="" selected="selected">Select a District</option>
<?php
while($dd2 = pg_fetch_array( $resultDist ))
{
echo '<option value= "' . $dd2['distname'] . '">' . $dd2['distname'] . '</option>';
}
?>
</select>
<?php
pg_close($con);
?>
目前它填充下拉列表中的所有divname和distname,但我想如果选择“Dhaka”,只有dhaka下的distname将在第二个下拉列表中显示。
由于
答案 0 :(得分:-1)
中应该有
where
条款
$distquery = "SELECT DISTINCT distname FROM union_bgd ORDER BY distname";
像这样编辑,
$distquery = "SELECT DISTINCT distname FROM union_bgd where divname=".$selected_dist." ORDER BY distname";