-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathambil_menu.php
More file actions
37 lines (31 loc) · 948 Bytes
/
Copy pathambil_menu.php
File metadata and controls
37 lines (31 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
header("Content-Type: application/json");
// Koneksi database
$conn = new mysqli("localhost", "root", "", "ngantriless");
if ($conn->connect_error) {
echo json_encode(["status" => "error", "message" => "Koneksi ke database gagal"]);
exit;
}
// Ambil hanya menu yang aktif (status = 1)
$query = "SELECT * FROM menu WHERE status = 1 ORDER BY created_at DESC";
$result = $conn->query($query);
$menu = [];
while ($row = $result->fetch_assoc()) {
// Fallback gambar jika file tidak ditemukan
$gambar = (isset($row["gambar"]) && file_exists($row["gambar"])) ? $row["gambar"] : "img/default.jpg";
$menu[] = [
"id" => $row["id"],
"id_toko" => $row["id_toko"],
"nama" => $row["nama"],
"harga" => $row["harga"],
"gambar" => $gambar,
"status" => $row["status"],
"created_at" => $row["created_at"]
];
}
// Kirim response JSON
echo json_encode([
"status" => "success",
"data" => $menu
]);
$conn->close();