<?php
include('session.php');

if (!isset($_POST['division_id']) || !isset($_POST['department_id'])) {
    exit;
}

$division_id = (int)$_POST['division_id'];
$department_id = (int)$_POST['department_id'];

$q = $conn->query("SELECT id, name FROM colonies 
                   WHERE division_id = '$division_id'
                   AND department_id = '$department_id'
                   ORDER BY name ASC");



if ($q && $q->num_rows > 0) {
    while ($row = $q->fetch_assoc()) {
        echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
    }
} else {
    echo '<option value="">No Colony Found</option>';
}
?>