mirror of
https://github.com/Alvin-Zilverstand/Schoolkantine.git
synced 2026-03-06 13:26:27 +01:00
Add order management functionality with order overview, retrieval, and completion features
This commit is contained in:
27
website/get_orders.php
Normal file
27
website/get_orders.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
include 'config.php';
|
||||
|
||||
// Set header to JSON
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Fetch orders from the database
|
||||
$sql = "SELECT order_number, items, total_price, order_time FROM orders ORDER BY order_time DESC";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result === false) {
|
||||
error_log("Failed to fetch orders: " . $conn->error);
|
||||
echo json_encode(['error' => 'Failed to fetch orders']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$orders = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$row['items'] = json_decode($row['items'], true); // Decode the JSON items
|
||||
$row['total_price'] = (float)$row['total_price']; // Ensure total_price is a number
|
||||
$orders[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode($orders);
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user