[英]Populate 2nd dropdown based on 1st dropdown selected in PHP
I am using PHP and Postgresql/PostGIS data base. 我正在使用PHP和Postgresql / PostGIS数据库。 My database schema is something like this.
我的数据库架构是这样的。
I am using the following codes 我正在使用以下代码
<?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);
?>
Currently its populating all the divname and distname in the dropdown but I want if the "Dhaka" is selected only the distname under the dhaka will show in the second dropdown. 当前,它在下拉列表中填充所有divname和distname,但我想如果选择“ Dhaka”,则仅在dhaka下的distname将显示在第二个下拉列表中。
Thanks 谢谢
There should be where
clause in 应该有
where
子句
$distquery = "SELECT DISTINCT distname FROM union_bgd ORDER BY distname";
Edit like this, 像这样编辑
$distquery = "SELECT DISTINCT distname FROM union_bgd where divname=".$selected_dist." ORDER BY distname";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.