-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetUserOrders.php
38 lines (34 loc) · 1.05 KB
/
getUserOrders.php
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
38
<?php
header("Access-Control-Allow-Origin: *"); // Allow requests from any origin
header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); // Allow specific HTTP methods
header("Access-Control-Allow-Headers: Content-Type, Authorization"); // Allow specific headers
header('Content-Type: application/json'); // Keep the content type as JSON
include 'Conx.php';
$sql = "
SELECT
o.user_id,
u.name AS user_name,
u.email AS user_email,
GROUP_CONCAT(p.name) AS product_names,
GROUP_CONCAT(o.quantity) AS quantities,
GROUP_CONCAT(o.price) AS prices,
SUM(o.totalPrice) AS total_price,
o.order_date,
o.Address
FROM orders o
JOIN users u ON o.user_id = u.id
JOIN products p ON o.product_id = p.id
GROUP BY o.user_id, o.order_date
ORDER BY o.order_date DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$orders = [];
while ($row = $result->fetch_assoc()) {
$orders[] = $row;
}
echo json_encode($orders);
} else {
echo json_encode([]);
}
$conn->close();
?>