20 lines
561 B
PHP
20 lines
561 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
$conn = new mysqli("localhost", "root", "", "webgis");
|
|
|
|
$sql = "SELECT * FROM area_polygon";
|
|
$result = $conn->query($sql);
|
|
$data_area = array();
|
|
|
|
if ($result->num_rows > 0) {
|
|
while($row = $result->fetch_assoc()) {
|
|
// Mengubah string geojson dari database kembali menjadi Object JSON
|
|
// Ini wajib agar Leaflet.geoJSON() di Javascript bisa merendernya
|
|
$row['geojson'] = json_decode($row['geojson']);
|
|
$data_area[] = $row;
|
|
}
|
|
}
|
|
|
|
echo json_encode($data_area);
|
|
$conn->close();
|
|
?>
|