<?php

include "../../config/db.php";

/* GET DISTRICT ID SAFELY */

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

/* FETCH BLOCKS */

$query = mysqli_query($conn,"
SELECT id, block_name 
FROM blocks
WHERE district_id='$district_id'
ORDER BY block_name
");

/* DEFAULT OPTION */

echo "<option value=''>Select Block</option>";

/* OUTPUT BLOCKS */

while($row = mysqli_fetch_assoc($query))
{
echo "<option value='".$row['id']."'>".$row['block_name']."</option>";
}

?>