Initial Commit
This commit is contained in:
27
indexes/user/getCities.php
Normal file
27
indexes/user/getCities.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// Include your database connection script
|
||||
include '../connectDB.php';
|
||||
|
||||
// Get the state_id from the query string
|
||||
$stateId = isset($_GET['state_id']) ? intval($_GET['state_id']) : 0;
|
||||
|
||||
// Array to hold cities
|
||||
$cities = [];
|
||||
|
||||
// Fetch cities from the database based on state_id
|
||||
if ($stateId > 0) {
|
||||
$query = "SELECT `id`, `name` FROM cities WHERE state_id = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("i", $stateId);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$cities[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the cities as JSON
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($cities);
|
||||
?>
|
||||
Reference in New Issue
Block a user