-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathambil_detail_pesanan.php
More file actions
34 lines (29 loc) · 915 Bytes
/
Copy pathambil_detail_pesanan.php
File metadata and controls
34 lines (29 loc) · 915 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
<?php
header('Content-Type: application/json');
$conn = new mysqli("localhost", "root", "", "ngantriless");
if ($conn->connect_error) {
echo json_encode(["status" => "error", "message" => "Koneksi gagal"]);
exit;
}
$id = $_GET['id'] ?? 0;
if (!$id) {
echo json_encode(["status" => "error", "message" => "ID tidak valid"]);
exit;
}
// Ambil pesanan utama
$qPesanan = $conn->prepare("SELECT total FROM pesanan WHERE id = ?");
$qPesanan->bind_param("i", $id);
$qPesanan->execute();
$pesanan = $qPesanan->get_result()->fetch_assoc();
// Ambil detail pesanan
$qDetail = $conn->prepare("SELECT nama_menu, harga, quantity FROM pesanan_detail WHERE id_pesanan = ?");
$qDetail->bind_param("i", $id);
$qDetail->execute();
$items = $qDetail->get_result()->fetch_all(MYSQLI_ASSOC);
echo json_encode([
"status" => "success",
"total" => $pesanan['total'],
"items" => $items
]);
$conn->close();
?>