<?php 
// Include the database config file 
include_once 'connect.php'; 
// Check connection
  if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
            }
 
if(!empty($_POST["district_id"])){ 
    // Fetch tehsil data based on the specific district 
    $query = "SELECT * FROM tehsils WHERE district_id = ".$_POST['district_id']." AND status = 1 ORDER BY tehsil_name ASC"; 
    $result = $conn->query($query); 
     
    // Generate HTML of tehsil options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select Tehsil</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['tehsil_id'].'">'.$row['tehsil_name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">Tehsil Not Available</option>'; 
    } 
}elseif(!empty($_POST["tehsil_id"])){ 
    // Fetch Constituency data based on the specific tehsil 
    $query = "SELECT * FROM constituency WHERE tehsil_id = ".$_POST['tehsil_id']." AND status = 1 ORDER BY cons_name ASC"; 
    $result = $conn->query($query); 
     
    // Generate HTML of Constituency options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select Constituency</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['cons_id'].'">'.$row['cons_name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">Constituency Not Available</option>'; 
    } 
}elseif(!empty($_POST["cons_id"])){ 
    // Fetch Union_Council data based on the specific Constituency 
    $query = "SELECT * FROM union_councils WHERE cons_id = ".$_POST['cons_id']." AND status = 1 ORDER BY uc_name ASC"; 
    $result = $conn->query($query); 
     
    // Generate HTML of Union_Council options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select Union Council</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['uc_id'].'">'.$row['uc_name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">Union Council Not Available</option>'; 
    } 
}elseif(!empty($_POST["uc_id"])){ 
    // Fetch Union_Council data based on the specific Constituency 
    $query = "SELECT * FROM school_level ORDER BY level_name ASC"; 
    $result = $conn->query($query); 
     
    // Generate HTML of School Level options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select School Level</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['level_id'].'">'.$row['level_name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">School Level Not Available</option>'; 
    } 
}
elseif(!empty($_POST["level_id"])){ 
    // Fetch School Category data based on the specific School Level 
    $query = "SELECT * FROM school_cate ORDER BY school_type ASC"; 
    $result = $conn->query($query); 
     
    // Generate HTML of School Type options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Select School Category</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['cate_id'].'">'.$row['school_type'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">School Level Not Available</option>'; 
    } 
}
// Close the database connection
            $conn->close();
?>