<?php
//Include database configuration file
include('conn.php');

mysql_query("SET character_set_results=utf8");

if(isset($_POST["district"]) && !empty($_POST["district"])){
    //Get all state data
	
	$sql="SELECT id, police_station_ban FROM police_station_list WHERE district_id = '".$_POST['district']."' ORDER BY police_station_ban ASC";
	//echo $sql;
	$query=mysql_query($sql);
	//echo "<option>$sql</option>";
	//echo "<option>".mysql_num_rows($query)."</option>";
	
    if(mysql_num_rows($query)>0){
        echo '<option value="">Select Police Station</option>';
        while($row=mysql_fetch_array($query)){ 
            echo '<option value="'.$row['id'].'">'.$row['police_station_ban'].'</option>';
        }
    }else{
        echo '<option value="">PS not available</option>';
    }
}

if(isset($_POST["police_station"]) && !empty($_POST["police_station"])){
	 //Get all state data
	
	$sql="SELECT id, post_office_ban FROM post_office_list WHERE police_station_id = ".$_POST['police_station']." ORDER BY post_office_ban ASC";
	//echo $sql;
	$query=mysql_query($sql);
	
    if(mysql_num_rows($query)>0){
        echo '<option value="">Select Post Office</option>';
        while($row=mysql_fetch_array($query)){ 
            echo '<option value="'.$row['id'].'">'.$row['post_office_ban'].'</option>';
        }
    }else{
        echo '<option value="">PO not available</option>';
    }
}

if(isset($_POST["id"]) && !empty($_POST["id"])){
	 //Get all state data
	$sql="SELECT post_code FROM post_office_list WHERE id = ".$_POST['id']."";
	//echo $sql;
	$query=mysql_query($sql);
	
    if(mysql_num_rows($query)>0){
        $row=mysql_fetch_array($query);
        echo $row['post_code'];
    }else{
        echo "NA";
    }
}

?>