<?php
include_once 'connect.php';

$district_id = $_POST['district_id'];
$query = "SELECT tehsil_id AS id, tehsil_name FROM tehsils WHERE status = 1";
if ($district_id) {
    $query .= " AND district_id = $district_id";
}
$query .= " ORDER BY tehsil_name ASC";

$result = $conn->query($query);
$options = "<option value=''>All Tehsils</option>";
while ($row = $result->fetch_assoc()) {
    $options .= "<option value='" . $row['id'] . "'>" . $row['tehsil_name'] . "</option>";
}
echo $options;
?>
