<?php
include_once 'connect.php';

$tehsil_id = $_POST['tehsil_id'];
$query = "SELECT cons_id as id, cons_name FROM constituency WHERE status = 1";
if ($tehsil_id) {
    $query .= " AND tehsil_id = $tehsil_id";
}
$query .= " ORDER BY cons_name ASC";

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