30 lines
729 B
PHP
30 lines
729 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
include __DIR__ . '/../../db_config.php';
|
|
|
|
$sql = "SELECT id, latitude, longitude, jenis_kerusakan, deskripsi, severity, gambar, created_at
|
|
FROM jalan_rusak
|
|
ORDER BY created_at DESC";
|
|
|
|
$result = $conn->query($sql);
|
|
$data = [];
|
|
|
|
if (!$result) {
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => 'Query gagal: ' . $conn->error]);
|
|
$conn->close();
|
|
exit;
|
|
}
|
|
|
|
if ($result && $result->num_rows > 0) {
|
|
while ($row = $result->fetch_assoc()) {
|
|
$row['latitude'] = (float)$row['latitude'];
|
|
$row['longitude'] = (float)$row['longitude'];
|
|
$data[] = $row;
|
|
}
|
|
}
|
|
|
|
echo json_encode($data);
|
|
$conn->close();
|
|
?>
|