-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsale.php
46 lines (42 loc) · 1.52 KB
/
sale.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
39
40
41
42
43
44
45
46
<?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') {
$stmt = $conn->prepare("
SELECT p.id, p.name AS product, p.image, p.price, m.percentage
FROM makesale m
JOIN products p ON m.product_id = p.id
WHERE p.status = 0 -- Fetch only products with status = 0
AND m.percentage IS NOT NULL -- Ensure percentage is filled
AND p.name IS NOT NULL -- Ensure product name is filled
");
if ($stmt) {
if ($stmt->execute()) {
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$products = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode(['success' => true, 'data' => $products]);
} else {
echo json_encode(['success' => false, 'message' => 'No products found']);
}
} else {
echo json_encode([
'success' => false,
'message' => 'Failed to execute the query',
'error' => $conn->error
]);
}
} else {
echo json_encode([
'success' => false,
'message' => 'Failed to prepare the SQL query',
'error' => $conn->error
]);
}
$stmt->close();
}
$conn->close();
?>