forked from hemang-mishra/DBMSProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_order.php
More file actions
94 lines (85 loc) · 3.07 KB
/
c_order.php
File metadata and controls
94 lines (85 loc) · 3.07 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
session_start();
// Ensure the user is logged in
if (!isset($_SESSION['user_id'])) {
echo "You must be logged in to view your order history.";
exit;
}
// Include the database connection file
require_once 'db_connection.php';
// Logged-in user ID
$user_id = $_SESSION['user_id'];
// Fetch orders for the logged-in user
$sql = "
SELECT
orders.order_id,
orders.date,
orders.price,
orders.amount,
orders.status, -- Add status field
crop.c_name AS crop_name,
crop.img_url AS crop_image
FROM orders
JOIN crop ON orders.c_id = crop.c_id
WHERE orders.u_id = ?
ORDER BY orders.date DESC
";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order History</title>
<link rel="stylesheet" href="css/c_order.css"> <!-- External CSS -->
<link rel="stylesheet" href="styles.css"> <!-- Link to external CSS in css folder-->
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<?php include("header.php"); ?>
<header>
<h1>Your Order History</h1>
</header>
<div class="order-container">
<?php
// Display orders in stacked blocks
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$order_id = $row['order_id'];
$crop_name = htmlspecialchars($row['crop_name']);
$quantity = htmlspecialchars($row['amount']);
$price = htmlspecialchars($row['price']);
$date = htmlspecialchars($row['date']);
$status = htmlspecialchars($row['status']); // Add status
$image_url = htmlspecialchars($row['crop_image'] ?? "https://via.placeholder.com/60"); // Fallback if no image
// Determine status display
$status_text = ($status === "Completed") ? "✔ Completed" : "⌛ Pending";
echo "
<div class='order-block' onclick=\"window.location.href='order_details.php?order_id=$order_id'\">
<div class='order-image'>
<img src='$image_url' alt='$crop_name'>
</div>
<div class='order-details'>
<h3>$crop_name</h3>
<p>Quantity: $quantity</p>
<p>Price: ₹$price</p>
<p>Date: $date</p>
<p class='order-status'>$status_text</p> <!-- Status -->
</div>
</div>
";
}
} else {
echo "<p>You have not placed any orders yet.</p>";
}
$stmt->close();
$conn->close();
?>
</div>
</body>
</html>