<?php

header("Content-Type: application/json");
require_once("../config/db.php");

$block_id = intval($_GET['block_id'] ?? 0);

if (!$block_id) {
    echo json_encode(["status" => false, "message" => "Block ID required"]);
    exit;
}

$query = "SELECT id, village_name FROM villages 
          WHERE block_id = '$block_id' 
          ORDER BY village_name ASC";

$result = $conn->query($query);

$data = [];

while ($row = $result->fetch_assoc()) {
    $data[] = $row;
}

echo json_encode([
    "status" => true,
    "data" => $data
]);