fix : dockerfile
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// ========================================
|
||||
// FILE: php/ambil_data_masyarakat.php
|
||||
// Mengambil data masyarakat miskin
|
||||
// ========================================
|
||||
|
||||
include 'koneksi.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
|
||||
// Kumpulkan filter dulu SEBELUM query dibuat
|
||||
$filters = [];
|
||||
$params = [];
|
||||
$types = "";
|
||||
|
||||
if (!empty($_GET['kecamatan'])) {
|
||||
$filters[] = "kecamatan = ?";
|
||||
$params[] = $_GET['kecamatan'];
|
||||
$types .= "s";
|
||||
}
|
||||
|
||||
if (!empty($_GET['status_bpjs'])) {
|
||||
$filters[] = "status_bpjs = ?";
|
||||
$params[] = $_GET['status_bpjs'];
|
||||
$types .= "s";
|
||||
}
|
||||
|
||||
if (!empty($_GET['search'])) {
|
||||
$filters[] = "(nama LIKE ? OR alamat LIKE ?)";
|
||||
$searchParam = "%" . $_GET['search'] . "%";
|
||||
$params[] = $searchParam;
|
||||
$params[] = $searchParam;
|
||||
$types .= "ss";
|
||||
}
|
||||
|
||||
// Susun query dengan urutan benar: WHERE dulu, baru ORDER BY
|
||||
$query = "SELECT * FROM masyarakat_miskin";
|
||||
|
||||
if (!empty($filters)) {
|
||||
$query .= " WHERE " . implode(" AND ", $filters);
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user