0

我正在使用 PHP 和 Postgresql/PostGIS 数据库。我的数据库架构是这样的。

  1. 名称 | 区名
  2. 达卡 | 马尼克甘杰
  3. 达卡 | 纳拉扬甘杰
  4. 达卡 | 蒙希甘杰
  5. 库尔纳 | 杰索尔
  6. 库尔纳 | 库什蒂亚
  7. 库尔纳 | 梅赫布尔

我正在使用以下代码

<?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 将显示在第二个下拉列表中。

谢谢

4

1 回答 1

-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";
于 2013-05-14T08:08:45.577 回答