<?php

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

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

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

$query = "SELECT id, name FROM blocks 
          WHERE district_id = '$district_id' 
          ORDER BY name ASC";

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

$data = [];

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

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