I am new in PHP. I have a database like the attached in the dropbox file. It has 4 column
- Division Name
- District Name
- Thana Name
- 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>