<?php
header('Content-Type: application/json');
include 'conex.php';

$id_zona = intval($_GET['id_zona'] ?? 0);
if ($id_zona <= 0) {
    echo json_encode([
        ['id' => '', 'canton' => '--- Seleccione ---']
    ]);
    exit;
}

$sql = "SELECT id, canton FROM tb_canton WHERE id_zona = $id_zona ORDER BY canton";
$res = mysqli_query($conex, $sql);

$cantones = [];
// Agregar opción vacía
$cantones[] = [
    'id' => '',
    'canton' => '--- Seleccione ---'
];

while ($row = mysqli_fetch_assoc($res)) {
    $cantones[] = $row;
}

echo json_encode($cantones);
?>
