与PHP和mysql数据库相关的下拉列表

I am new in PHP. I have a database like the attached in the dropbox file. It has 4 column

  1. Division Name
  2. District Name
  3. Thana Name
  4. Union name

These are the administrative unit of our country. I want to create four dropdown list/combobox those will populate from the database. One thing is must to related each other. If someone select Division name it will show only the district name those are belongs to that Division. Similarly if the district selected it will only show Thana name in the 3rd dropdown list. Similarly the 4th dropdown will be filled up.

Database Schema:

https://dl.dropboxusercontent.com/u/81313785/database_schema.xls

Here is the code I used:

  <?php
$con = pg_connect("data connection");
if (!$con)
  {
  die("Could not connect: " . pg_last_error());
  }

  $locfindsql = "SELECT unionname, thananame, distname, divname from union_bgd";

//echo $sql;
$result = pg_query($con, $locfindsql);

$row = array();
?>
<div id="leftpanel" style="position: absolute; top: 12%; left: 1%; bottom: 2%; width: 20%; height: 86%; box-shadow: 4px 4px 4px #888888;
         background: #5e5e5c; z-index:-888;">

    <div id="findPlace" style= "position: absolute; left: 8px; top: 8px; right: 8px; height: 275px; background: rgb(245, 246, 246); border-radius: 4px;" >
        <h4>Find a location</h4>
        Division:</br>
        <select name="Division">
            <?
            while($row = pg_fetch_array($result))
              {
              echo "<option>$row[divname]</option>";
              }
            ?>
        </select></br>
        District:</br>
        <select name="District">
            <?
            while($row = pg_fetch_array($result))
              {
              echo "<option>$row[distname]</option>";
              }
            ?>
        </select></br>
        Upazila:</br>
        <select name="Union">
            <?
            while($row = pg_fetch_array($result))
              {
              echo "<option>$row[thananame]</option>";
              }
            ?>
        </select></br>
        Union:</br>
        <select name="Union">
            <?
            while($row = pg_fetch_array($result))
              {
              echo "<option>$row[unionname]</option>";
              }
            ?>
        </select></br>
            <?
            pg_close($con);
            ?>

        <button id="placebutton" style="font-size: small; font-family: Arial;"><a href="javascript:onPlaceBtnClick('findPlaceButton')">Find the Place</a></button>
    </div>

    </div>

I'm not sure if this is the kind of thing you're talking about but I hope it will be of help to you. This is code populates a drop down list from the database. This isn't production code but it shows one way to feed the database results into the form. If you're totally new to PHP and want to learn the basics quickly, you can try w3schools.com and see if it's helpful for you. There's also documentation at php.net where you can dive into the depths of PHP.

    // GET LIST AND DISPLAY IN FORM
    $link = mysqli_connect($db_connection, $db_user, $db_passwd, $db_name);
    // check connection
    if (mysqli_connect_errno()) 
    {
      printf("Connect failed: %s
", mysqli_connect_error());
      exit();
    }
    // else echo "<p>Connected to database.</p>";
    // Get value for new student id 
    $query = "SELECT custid, firstname, lastname FROM customer ORDER BY lastname, firstname ASC";
    if($result = mysqli_query($link, $query)) 
    {
        echo '<p><form action="./index.php" method="post">';
        //
        //SELECT THE CUSTOMER MAKING THE PAYMENT
        echo'<select name="loadcustomer">';
        echo'<option value="" selected="selected" disabled="disabled">Select a Customer</option>';
        while ($idresult = mysqli_fetch_row($result))
        {
            $custid = $idresult[0];
            $firstname = $idresult[1];
            $lastname = $idresult[2];

            echo'<option value="' . $custid . '">' . $firstname . '&nbsp;' . $lastname . '</option>';
        }
        echo'</select></p><p>';
        //
        // SELECT THE NUMBER OF HOURS TO BE PAID
        echo'<select name="numberofhours">';
        echo'<option value="" selected="selected" disabled="disabled">Select # of Hours</option>';
        echo'<option value="1">1</option>';
        echo'<option value="2">2</option>';
        echo'<option value="3">3</option>';
        echo'<option value="4">4</option>';
        echo'<option value="5">5</option>';
        echo'<option value="6">6</option>';
        echo'<option value="7">7</option>';
        echo'<option value="8">8</option>';
        echo'</select></p><p>';
        echo'<input type="submit" value="Load Customer" />';
        echo'</form></p>';  
    }
    mysqli_free_result($result);
    // close connection 
    mysqli_close($link);

if i am understand correctly the following code will work correctly, just do mysql setting correctly

        <?php
    $con=mysqli_connect("your host","mysql_user","user_password","your_db");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    $result = mysqli_query($con,"SELECT destrict, thana FROM your table");
    ?>
    <select>
    <?
    while($row = mysqli_fetch_array($result))
      {
      echo "<option>$row[destrict]</option>";

      }
    ?>
    </select>
    <?
    mysqli_close($con);
    ?>