<?php

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
require_once('../lib/dbclass.php');



$conn = mysqli_connect('localhost', DB_USERNAME, DB_PASSWORD, DB_NAME);


$selectcondition = $_GET['selectcondition'];

$id = $_GET['id'];


if ($selectcondition == 1) {
    $query  = "SELECT id, name FROM tbl_assembly WHERE district = '$id' and status=0";
    $result = mysqli_query($conn, $query);



    $cityData = '<option value="">Select Assembly</option>'; // Default option
    while ($row = mysqli_fetch_assoc($result)) {
        $cityData .= '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    }
    echo json_encode($cityData);

    return;
} elseif ($selectcondition == 2) {
    $query  = "SELECT id, panchayat_name name FROM tbl_panchayat WHERE assembly_id = '$id' and status=0";
    $result = mysqli_query($conn, $query);



    $cityData = '<option value="">Select Panchayat</option>'; // Default option
    while ($row = mysqli_fetch_assoc($result)) {
        $cityData .= '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    }
    echo json_encode($cityData);

    return;
} else {
    $query  = "SELECT id, ward_name name FROM tbl_ward WHERE panchayat_id = '$id' and status=0";
    $result = mysqli_query($conn, $query);



    $cityData = '<option value="">Select Ward</option>'; // Default option
    while ($row = mysqli_fetch_assoc($result)) {
        $cityData .= '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    }
    echo json_encode($cityData);

    return;
}
