-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayProduct.php
29 lines (25 loc) · 1004 Bytes
/
DisplayProduct.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
<?php
include "Conx.php";
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// Include a WHERE clause to filter out products with status = 1
$stmt = $conn->prepare("
SELECT p.id, p.name, p.description, p.price, p.image, p.quantity, m.percentage, m.start_date, m.end_date
FROM products p
LEFT JOIN makesale m ON m.product_id = p.id
WHERE p.status = 0
");
if ($stmt->execute()) {
$result = $stmt->get_result();
$products = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode(['success' => true, 'data' => $products]);
} else {
echo json_encode(['success' => false, 'message' => 'Failed to retrieve products', 'error' => $conn->error]);
}
$stmt->close();
}
$conn->close();
?>