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

if(!empty($_POST["region_id"])){ 
    // Fetch state data based on the specific country 
    $query = "SELECT * FROM districts WHERE region_id = ".$_POST['region_id']." ORDER BY district_name ASC"; 
    $result = $conn->query($query); 
     
    // Generate HTML of state options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select District</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['district_id'].'">'.$row['district_name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">District not available</option>'; 
    } 
}elseif(!empty($_POST["district_id"])){ 
    // Fetch city data based on the specific state 
    $query = "SELECT * FROM wards WHERE district_id = ".$_POST['district_id']." ORDER BY ward_name ASC"; 
    $result = $conn->query($query); 
     
    // Generate HTML of city options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select Ward</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['ward_id'].'">'.$row['ward_name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">Designation not available</option>'; 
    } 
}


/*
if(!empty($_POST["dept_id"])){
	
	
    //Get all state data
    $query = $conn->query("SELECT * FROM sections WHERE dept_id = ".$_POST['dept_id']." ORDER BY sect_name");
    
    //Count total number of rows
    $rowCount = $query->num_rows;
    
    //Display states list
    if($rowCount > 0){
        //echo '<option value="">Chagua Kata</option>';
        while($row = $query->fetch_assoc()){ 
            echo '<option value="'.$row['sect_id'].'">'.$row['sect_name'].'</option>';
        }
    }else{
        echo '<option value="">No Section </option>';
    }
	

			
}
*/

?>