This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct-list.php
432 lines (413 loc) · 18.3 KB
/
product-list.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<!doctype html>
<html class="no-js" lang="en">
<?php
include_once 'elements\head.php';
include_once 'config\conn.php';
?>
<body>
<div class="wrapper bg-dark-white">
<?php include_once 'elements\header.php' ?>
<div class="heading-banner-area overlay-bg">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="heading-banner">
<div class="heading-banner-title">
<h2>Product View</h2>
</div>
<div class="breadcumbs pb-15">
<ul>
<li><a href="#">Home</a></li>
<li>Product view</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="product-area pt-80 pb-80 product-style-2">
<div class="container">
<div class="row">
<div class="col-lg-3 order-2 order-lg-1">
<aside class="widget widget-search mb-30">
<form action="" method="GET">
<input type="text" name="search" placeholder="Search here...">
<button type="submit">Search</button>
</form>
</aside>
<aside class="widget widget-categories mb-30">
<div class="widget-title">
<h4>Categories</h4>
</div>
<div id="cat-treeview" class="widget-info product-cat boxscrol2">
<ul>
<?php
$sql = "SELECT * FROM product_type";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<li><span><a href="?category=' . $row['name'] . '">' . $row['name'] . '<a></span>';
echo '</li>';
}
} else {
echo "0 results";
}
?>
</ul>
</div>
</aside>
<aside class="widget shop-filter mb-30">
<div class="widget-title">
<h4>Price</h4>
</div>
<div class="widget-info">
<div class="price_filter">
<div class="price_slider_amount">
<form action="" method="GET">
<input type="number" min="0" step="50" max="5000" name="min-price"
placeholder="50$">
<input type="number" min="0" step="100" max="5000" name="max-price"
placeholder="1000$">
<button type="submit">Search</button>
</form>
</div>
</div>
</div>
</aside>
<aside class="widget widget-color mb-30">
<div class="widget-title">
<h4>Brands</h4>
</div>
<div class="widget-info color-filter clearfix">
<ul>
<?php
$sql = "SELECT * FROM brand";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$sql2 = "SELECT COUNT(*) AS total FROM product WHERE brand_id = " . $row['id'];
$result2 = mysqli_query($conn, $sql2);
$row2 = mysqli_fetch_assoc($result2);
echo '<li><a href="?brandID=' . $row['id'] . '"><span></span>' . $row['name'] . '<span
class="count">' . $row2['total'] . '</span></a></li>';
}
} else {
echo "0 results";
}
?>
</ul>
</div>
</aside>
<aside class="widget widget-banner hidden-sm">
<div class="widget-info widget-banner-img">
<a href="#"><img src="img/banner/5.jpg" alt="" /></a>
</div>
</aside>
</div>
<div class="col-lg-9 order-1 order-lg-2">
<div class="shop-content mt-tab-30 mb-30 mb-lg-0">
<div class="product-option mb-30 clearfix">
<ul class="nav d-block shop-tab">
<li><a class="active" href="#grid-view" data-bs-toggle="tab"><i
class="zmdi zmdi-view-module"></i></a></li>
</ul>
<div class="showing text-end d-none d-md-block">
<?php
// Lấy tổng số sản phẩm
$sql = "SELECT COUNT(*) AS total FROM product";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$total_products = $row['total'];
// Tính toán số trang
$products_per_page = 9;
$total_pages = ceil($total_products / $products_per_page);
$current_page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = ($current_page - 1) * $products_per_page;
// in số lượng sản phẩm đã in ra màn hình và tổng số lượng sản phẩm
$from = $offset + 1;
$to = $offset + $products_per_page;
if ($to > $total_products) {
$to = $total_products;
}
echo "<p class='mb-0'>Showing $from-$to of $total_products Results</p>";
?>
</div>
</div>
<div class="tab-content">
<div class="tab-pane active" id="grid-view">
<div class="row">
<?php
// Lấy tổng số sản phẩm
$sql = "SELECT COUNT(*) AS total FROM product";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$total_products = $row['total'];
// Tính toán số trang
$products_per_page = 9;
$total_pages = ceil($total_products / $products_per_page);
// Lấy sản phẩm trên trang hiện tại
$current_page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = ($current_page - 1) * $products_per_page;
$sql = "SELECT * FROM product LIMIT $offset, $products_per_page";
$result = mysqli_query($conn, $sql);
if (isset($_GET['search'])) {
$search = $_GET['search'];
$sql = "SELECT * FROM product WHERE name LIKE '%$search%'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="col-lg-4 col-md-6">
<div class="single-product">
<div class="product-img">
<span class="pro-price-2">$ ' . $row['price_out'] . '
</span>
<a href="single-product.html"><img src="admin/' . $row['thumbnail'] . '" alt="" style="height:270px" />
</a>
</div>
<div class="product-info clearfix text-center">
<div class="fix">
<h4 class="post-title"><a href="product.php?product=' . $row['id'] . '">' . $row['name'] . '</a>
</h4>
</div>
<div class="fix">
</div>
<div class="product-action clearfix">
<a href="wishlist.html" data-bs-toggle="tooltip"
data-placement="top" title="Wishlist"><i
class="zmdi zmdi-favorite-outline"></i></a>
<a href="#" data-bs-toggle="modal" data-bs-target="#productModal"
title="Quick View"><i class="zmdi zmdi-zoom-in"></i></a>
<a href="#" data-bs-toggle="tooltip" data-placement="top"
title="Compare"><i class="zmdi zmdi-refresh"></i></a>
<form method="post" action="">
<input type="hidden" name="product_id" value="' . $row['id'] . '">
<input type="hidden" name="product_quantity" value="1">
<input type="hidden" name="product_name" value="' . $row['name'] . '">
<input type="hidden" name="product_price" value="' . $row['price_out'] . '">
<button type="submit" class="btn" name="add-to-cart">
<i class="zmdi zmdi-shopping-cart-plus"></i>
</button>
</form>
</div>
</div>
</div>
</div>';
}
} else {
echo '<div style="padding: 30px"><h2 style="text-align: center;">0 results</h2></div>';
}
}
// lấy sản phẩm theo giá
if (isset($_GET['min-price']) && isset($_GET['max-price'])) {
// tìm kiểm dựa theo khoảng giá của sản phẩm
$min_price = $_GET['min-price'];
$max_price = $_GET['max-price'];
$sql = "SELECT * FROM product WHERE price_out BETWEEN $min_price AND $max_price";
// query sql
$result = mysqli_query($conn, $sql);
// fetch data
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="col-lg-4 col-md-6">
<div class="single-product">
<div class="product-img">
<span class="pro-price-2">$ ' . $row['price_out'] . '</span>
<a href="single-product.html"><img src="admin/' . $row['thumbnail'] . '" alt="" style="height:270px" /></a>
</div>
<div class="product-info clearfix text-center">
<div class="fix">
<h4 class="post-title"><a href="product.php?product=' . $row['id'] . '">' . $row['name'] . '</a></h4>
</div>
<div class="fix">
</div>
<div class="product-action clearfix">
<a href="wishlist.html" data-bs-toggle="tooltip"
data-placement="top" title="Wishlist"><i
class="zmdi zmdi-favorite-outline"></i></a>
<a href="#" data-bs-toggle="modal" data-bs-target="#productModal"
title="Quick View"><i class="zmdi zmdi-zoom-in"></i></a>
<a href="#" data-bs-toggle="tooltip" data-placement="top"
title="Compare"><i class="zmdi zmdi-refresh"></i></a>
<form method="post" action="">
<input type="hidden" name="product_id" value="' . $row['id'] . '">
<input type="hidden" name="product_quantity" value="1">
<input type="hidden" name="product_name" value="' . $row['name'] . '">
<input type="hidden" name="product_price" value="' . $row['price_out'] . '">
<button type="submit" class="btn" name="add-to-cart"><i class="zmdi zmdi-shopping-cart-plus"></i></button>
</form>
</div>
</div>
</div>
</div>';
}
} else {
echo '<div style="padding: 30px"><h2 style="text-align: center;">0 results</h2></div>';
}
}
// lấy sản phẩm theo danh mục
if (isset($_GET['category'])) {
$category = $_GET['category'];
$sql = "SELECT * FROM product_type WHERE name = '$category'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$category_id = $row['id'];
$sql = "SELECT * FROM product WHERE product_type_id = $category_id";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="col-lg-4 col-md-6">
<div class="single-product">
<div class="product-img">
<span class="pro-price-2">$ ' . $row['price_out'] . '</span>
<a href="single-product.html"><img src="admin/' . $row['thumbnail'] . '" alt="" style="height:270px" /></a>
</div>
<div class="product-info clearfix text-center">
<div class="fix">
<h4 class="post-title"><a href="product.php?product=' . $row['id'] . '">' . $row['name'] . '</a></h4>
</div>
<div class="fix">
</div>
<div class="product-action clearfix">
<a href="wishlist.html" data-bs-toggle="tooltip"
data-placement="top" title="Wishlist"><i
class="zmdi zmdi-favorite-outline"></i></a>
<a href="#" data-bs-toggle="modal" data-bs-target="#productModal"
title="Quick View"><i class="zmdi zmdi-zoom-in"></i></a>
<a href="#" data-bs-toggle="tooltip" data-placement="top"
title="Compare"><i class="zmdi zmdi-refresh"></i></a>
<form method="post" action="">
<input type="hidden" name="product_id" value="' . $row['id'] . '">
<input type="hidden" name="product_quantity" value="1">
<input type="hidden" name="product_name" value="' . $row['name'] . '">
<input type="hidden" name="product_price" value="' . $row['price_out'] . '">
<button type="submit" class="btn" name="add-to-cart"><i class="zmdi zmdi-shopping-cart-plus"></i></button>
</form>
</div>
</div>
</div>
</div>';
}
} else {
echo '<div style="padding: 30px"><h2 style="text-align: center;">0 results</h2></div>';
}
}
// lấy sản phẩm theo thương hiệu
if (isset($_GET['brandID'])) {
$brandID = $_GET['brandID'];
$sql = "SELECT * FROM product WHERE brand_id = $brandID";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="col-lg-4 col-md-6">
<div class="single-product">
<div class="product-img">
<span class="pro-price-2">$ ' . $row['price_out'] . '</span>
<a href="single-product.html"><img src="admin/' . $row['thumbnail'] . '" alt="" style="height:270px" /></a>
</div>
<div class="product-info clearfix text-center">
<div class="fix">
<h4 class="post-title"><a href="product.php?product=' . $row['id'] . '">' . $row['name'] . '</a></h4>
</div>
<div class="fix">
</div>
<div class="product-action clearfix">
<a href="wishlist.html" data-bs-toggle="tooltip"
data-placement="top" title="Wishlist"><i
class="zmdi zmdi-favorite-outline"></i></a>
<a href="#" data-bs-toggle="modal" data-bs-target="#productModal"
title="Quick View"><i class="zmdi zmdi-zoom-in"></i></a>
<a href="#" data-bs-toggle="tooltip" data-placement="top"
title="Compare"><i class="zmdi zmdi-refresh"></i></a>
<form method="post" action="">
<input type="hidden" name="product_id" value="' . $row['id'] . '">
<input type="hidden" name="product_quantity" value="1">
<input type="hidden" name="product_name" value="' . $row['name'] . '">
<input type="hidden" name="product_price" value="' . $row['price_out'] . '">
<button type="submit" class="btn" name="add-to-cart"><i class="zmdi zmdi-shopping-cart-plus"></i></button>
</form>
</div>
</div>
</div>
</div>';
}
} else {
echo '<div style="padding: 30px"><h2 style="text-align: center;">0 results</h2></div>';
}
}
// Hiển thị sản phẩm trên trang hiện tại
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="col-lg-4 col-md-6">
<div class="single-product">
<div class="product-img">
<span class="pro-price-2">$ ' . $row['price_out'] . '</span>
<a href="single-product.html"><img src="admin/' . $row['thumbnail'] . '" alt="" style="height:270px" /></a>
</div>
<div class="product-info clearfix text-center">
<div class="fix">
<h4 class="post-title"><a href="product.php?product=' . $row['id'] . '">' . $row['name'] . '</a></h4>
</div>
<div class="fix">
</div>
<div class="product-action clearfix">
<a href="wishlist.html" data-bs-toggle="tooltip"
data-placement="top" title="Wishlist"><i
class="zmdi zmdi-favorite-outline"></i></a>
<a href="#" data-bs-toggle="modal" data-bs-target="#productModal"
title="Quick View"><i class="zmdi zmdi-zoom-in"></i></a>
<a href="#" data-bs-toggle="tooltip" data-placement="top"
title="Compare"><i class="zmdi zmdi-refresh"></i></a>
<form method="post" action="">
<input type="hidden" name="product_id" value="' . $row['id'] . '">
<input type="hidden" name="product_quantity" value="1">
<input type="hidden" name="product_name" value="' . $row['name'] . '">
<input type="hidden" name="product_price" value="' . $row['price_out'] . '">
<button type="submit" class="btn" name="add-to-cart"><i class="zmdi zmdi-shopping-cart-plus"></i></button>
</form>
</div>
</div>
</div>
</div>';
}
?>
</div>
</div>
</div>
<div class="shop-pagination text-center">
<div class="pagination">
<ul>
<?php
// Lấy tổng số sản phẩm
$sql = "SELECT COUNT(*) AS total FROM product";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$total_products = $row['total'];
// Tính toán số trang
$products_per_page = 9;
$total_pages = ceil($total_products / $products_per_page);
// Hiển thị phân trang
// hiển thị trang trước
if ($current_page > 1 && $total_pages > 1) {
echo '<li><a href="?page=' . ($current_page - 1) . '"><i class="zmdi zmdi-long-arrow-left"></i></a></li>';
}
for ($i = 1; $i <= $total_pages; $i++) {
echo "<li><a href='?page=$i'>$i</a></li> ";
}
// hiển thị trang sau
if ($current_page < $total_pages && $total_pages > 1) {
echo '<li><a href="?page=' . ($current_page + 1) . '"><i class="zmdi zmdi-long-arrow-right"></i></a></li>';
}
?>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include_once 'elements\footer.php' ?>
</div>
<?php include_once 'elements\js.php' ?>
</body>
</html>