21 lines
544 B
PHP
21 lines
544 B
PHP
<?php
|
|
require_once __DIR__ . '/../includes/app.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$countryId = isset($_GET['country_id']) ? (int)$_GET['country_id'] : 0;
|
|
|
|
if ($countryId <= 0) {
|
|
echo json_encode([]);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = db()->prepare("SELECT id, name_en, name_ar FROM cities WHERE country_id = ? ORDER BY name_en ASC");
|
|
$stmt->execute([$countryId]);
|
|
$cities = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
echo json_encode($cities);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
}
|