-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder_details.php
More file actions
164 lines (151 loc) · 4.59 KB
/
order_details.php
File metadata and controls
164 lines (151 loc) · 4.59 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
session_start();
include "db.php";
include "header.php";
if (!isset($_SESSION["user_id"])) {
header("Location: login.php");
exit();
}
// Get the order ID from the URL
$order_id = intval($_GET['id']);
// Fetch order details along with book titles
$stmt = $conn->prepare("
SELECT o.id AS order_id, o.total_price, o.status, o.transaction_id, o.mobile, o.created_at,
b.title AS book_name, oi.quantity, oi.price
FROM orders o
JOIN order_items oi ON o.id = oi.order_id
JOIN books b ON oi.book_id = b.id
WHERE o.id = ?
");
// Bind order ID parameter to the prepared SQL statement.
$stmt->bind_param("i", $order_id);
// Add HTML boilerplate with Bootstrap and custom styling for order details page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order Details</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
// Style body with background color and base font.
body {
background-color: #f4f7fc;
font-family: 'Arial', sans-serif;
}
// Design main container with padding, border-radius, and shadow.
.container {
max-width: 900px;
margin-top: 50px;
background-color: white;
padding: 30px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
// Style headings and order detail section.
h2 {
text-align: center;
color: #333;
font-size: 2.2rem;
margin-bottom: 30px;
}
.order-details {
font-size: 1.1rem;
color: #555;
margin-bottom: 20px;
}
.order-details strong {
font-weight: 600;
color: #333;
}
// Style list items and book info display inside order details.
.list-group-item {
background-color: #f9f9f9;
border: 1px solid #e0e0e0;
margin-bottom: 10px;
}
.list-group-item .book-info {
display: flex;
justify-content: space-between;
}
.list-group-item .book-info span {
font-size: 1rem;
color: #333;
}
// Style warning and error alerts for order messages.
.alert {
font-size: 1.1rem;
border-radius: 8px;
padding: 15px;
text-align: center;
}
.alert-warning {
background-color: #fff3cd;
color: #856404;
}
.alert-danger {
background-color: #f8d7da;
color: #721c24;
}
// Style footer section with background, text, and hover effect.
footer {
background-color: #343a40;
color: white;
padding: 20px;
text-align: center;
margin-top: 50px;
}
footer a {
color: #f8f9fa;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
// Execute the prepared statement and retrieve the result set.
<?php
if ($stmt->execute()) {
$result = $stmt->get_result();
// Check if order data exists and initialize container for output.
if ($result->num_rows > 0) {
$orderPrinted = false;
echo "<div class='container'>";
// Display order metadata like status, mobile, and transaction ID once.
while ($order = $result->fetch_assoc()) {
if (!$orderPrinted) {
echo "<h2>Order Details (Order ID: {$order['order_id']})</h2>";
echo "<div class='order-details'>
<p><strong>Total Price:</strong> \${$order['total_price']}</p>
<p><strong>Status:</strong> {$order['status']}</p>
<p><strong>Transaction ID:</strong> {$order['transaction_id']}</p>
<p><strong>Mobile:</strong> {$order['mobile']}</p>
<p><strong>Order Date:</strong> {$order['created_at']}</p>
</div>";
echo "<h4>Books in this Order:</h4><ul class='list-group'>";
$orderPrinted = true;
}
// Loop through each ordered book and display quantity and price.
echo "<li class='list-group-item'>
<div class='book-info'>
<span>{$order['book_name']}</span>
<span>Qty: {$order['quantity']} | Price: \${$order['price']}</span>
</div>
</li>";
}
echo "</ul></div>";
}
// Handle empty result or query execution failure with user-friendly messages.
else {
echo "<div class='container mt-5 alert alert-warning'>No order details found for this order ID.</div>";
}
} else {
echo "<div class='container mt-5 alert alert-danger'>Error executing query: " . $stmt->error . "</div>";
}
// Include footer and close HTML document structure.
include "footer.php"; // Include footer
?>
</body>
</html>