Files
Webgis/01/php/ambil_rumah_ibadah.php
T
2026-06-10 23:21:21 +07:00

47 lines
1.0 KiB
PHP

<?php
// ========================================
// FILE: php/ambil_rumah_ibadah.php
// Mengambil data rumah ibadah
// ========================================
include 'koneksi.php';
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// Susun query dengan urutan benar: WHERE dulu, baru ORDER BY
$query = "SELECT * FROM rumah_ibadah";
$params = [];
$types = "";
if (!empty($_GET['jenis'])) {
$query .= " WHERE jenis = ?";
$params[] = $_GET['jenis'];
$types .= "s";
}
$query .= " ORDER BY created_at DESC";
$stmt = $conn->prepare($query);
if ($stmt === false) {
sendJSON('error', 'Query prepare gagal: ' . $conn->error);
}
if (!empty($params)) {
$stmt->bind_param($types, ...$params);
}
if (!$stmt->execute()) {
sendJSON('error', 'Query gagal dieksekusi: ' . $stmt->error);
}
$result = $stmt->get_result();
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
sendJSON('success', 'Data berhasil diambil', $data);
}
?>