-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshop.php
More file actions
353 lines (309 loc) · 14.8 KB
/
Copy pathshop.php
File metadata and controls
353 lines (309 loc) · 14.8 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
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
<?php
include 'inc/session.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Shop | <?php
$link = mysqli_query($connect, "SELECT * FROM links WHERE id = 7");
$links = mysqli_fetch_array($link);
echo $links['link'];
?></title>
<?php include 'inc/link.php'; ?>
</head>
<body style="background-color: ghostwhite;">
<?php include 'inc/header.php'; ?>
<div class="col-md-11 mx-auto row mt-4">
<!-- All Categories -->
<div class="col-md-3">
<div class=" bg-white">
<h5 class="bg-light text-dark text-white py-2 border-top border-bottom border-danger" style="border-to: 5px solid #dc3545;"><span class="p-2">Categories <span class="fas fa-caret-down float-right px text-danger px-2"></span></span>
</h5>
<?php
$sql = mysqli_query($connect, "SELECT * FROM categories");
while ($row = mysqli_fetch_array($sql)) {
?>
<a href="?id=<?php echo $row['id'] ?>&&category=<?php echo $row['category'] ?>" class="text-dark">
<h6 class="p-3 border-bottom border-danger">
<?php echo $row['category']; ?>
<span class="fas fa-caret-right float-right text-danger"></span>
</h6>
</a>
<?php } ?>
</div>
</div>
<!-- Collections By Category -->
<div class="col-md-9 p-2">
<?php
if (isset($_GET['id']) && isset($_GET['category'])) {
$id = (int)$_GET['id'];
$category = $_GET['category'];
?>
<h5><?php echo $category; ?></h5>
<hr>
<?php
if (isset($_GET['page_no']) && $_GET['page_no']!="") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}
$total_records_per_page = 10;
$offset = ($page_no-1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$adjacents = "2";
$result_count = mysqli_query($connect,"SELECT COUNT(*) As total_records FROM `products` WHERE category = '{$id}'");
$total_records = mysqli_fetch_array($result_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $total_records_per_page);
$second_last = $total_no_of_pages - 1; // total page minus 1
$result = mysqli_query($connect, "SELECT * FROM `products` WHERE category = '{$id}' ORDER BY id DESC LIMIT $offset, $total_records_per_page");
while ($row = mysqli_fetch_array($result)) {
$image = $row['image'];
$product = $row['product'];
$description = $row['description'];
$date = $row['date'];
$category = $row['category'];
$id_post = $row['id'];
?>
<!--------------------- PRODUCT DESIGN ----------->
<div class="row mx-0 group mb-3 shadow p-2 bg-white">
<div class="col-md-4 mt-4 p-3">
<img src="upload/<?php echo $row['image'] ?>" class="card-img">
</div>
<div class="col-md-8 pl-3">
<a href="collections.php?product_id=<?php echo $row['id']; ?>&&product=<?php echo $row['product']; ?>" class="nav-link">
<h3 class=" pt-3 mb-2">
<?php echo $row['product']; ?>
</h3>
</a>
<b class="mt-2 mb-5 d-block">
<?php if ($row['status']==1) {
?>
<span class="fas fa-check bg-danger rounded-circle text-light p-1"></span>
In Stock!
<?php }else{ ?>
<span class="fas fa-times bg-danger rounded-circle text-light p-1"></span>
Out of Stock!
<?php } ?>
</b>
<a href="collections.php?product_id=<?php echo $row['id']; ?>&product=<?php echo $row['product']; ?>" class="text-uppercase">+ See full details here</a>
<br>
<div class="float-left mt-3">
<?php if ($row['old_price'] > 0): ?>
<h4 class="d-inline-block" style="text-decoration: line-through;">$<?php echo number_format($row['old_price'],2); ?></h4>
<?php endif ?>
<h2 class="d-inline-block text-danger" style="line-height: 25px;">$<?php echo number_format($row['price'],2); ?></h2> </div>
<div class="float-right mt-3">
<a href="collections.php?product_id=<?php echo $row['id'] ?>&product=<?php echo $row['product'] ?>"><button class="btn btn-danger">View Product</button></a>
</div>
<div class="clearfix"></div>
<div >
</div>
</div>
</div>
<?php } ?>
<ul class="pagination">
<?php // if($page_no > 1){ echo "<li><a href='?page_no=1'>First Page</a></li>"; } ?>
<li class="border-danger border" <?php if($page_no <= 1){ echo "class='disable'"; } ?>>
<a class="page-link" <?php if($page_no > 1){ echo "href='?page_no=$previous_page'"; } ?>><span class="fas fa-caret-left text-danger " title="Previous"></span></a>
</li>
<?php
if ($total_no_of_pages <= 10){
for ($counter = 1; $counter <= $total_no_of_pages; $counter++){
if ($counter == $page_no) {
echo "<li class='active page-link text-light bg-danger border border-danger'><a>$counter</a></li>";
}else{
echo "<li><a href='?page_no=$counter' class='page-link text-danger border border-danger'>$counter</a></li>";
}
}
}
elseif($total_no_of_pages > 10){
if($page_no <= 4) {
for ($counter = 1; $counter < 8; $counter++){
if ($counter == $page_no) {
echo "<li class='active page-link text-light bg-danger border border-danger'><a>$counter</a></li>";
}else{
echo "<li><a href='?page_no=$counter' class='page-link text-danger border border-danger'>$counter</a></li>";
}
}
echo "<li class=' text-danger border border-danger'><a>...</a></li>";
echo "<li class='border border-danger'><a href='?page_no=$second_last' class='text-danger'>$second_last</a></li>";
echo "<li class='border border-danger'><a href='?page_no=$total_no_of_pages' class='text-danger'>$total_no_of_pages</a></li>";
}
elseif($page_no > 4 && $page_no < $total_no_of_pages - 4) {
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=1'>1</a></li>";
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=2'>2</a></li>";
echo "<li class='border border-danger'><a class='text-danger'>...</a></li>";
for ($counter = $page_no - $adjacents; $counter <= $page_no + $adjacents; $counter++) {
if ($counter == $page_no) {
echo "<li class='active text-light bg-danger border border-danger'><a>$counter</a></li>";
}else{
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=$counter'>$counter</a></li>";
}
}
echo "<li class='border border-danger' text-danger><a>...</a></li>";
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=$second_last'>$second_last</a></li>";
echo "<li class='border border-danger'><a class='text-danger-danger' href='?page_no=$total_no_of_pages'>$total_no_of_pages</a></li>";
}
else {
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=1'>1</a></li>";
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=2'>2</a></li>";
echo "<li class='border border-danger text-danger'><a>...</a></li>";
for ($counter = $total_no_of_pages - 6; $counter <= $total_no_of_pages; $counter++) {
if ($counter == $page_no) {
echo "<li class='active bg-danger text-light'><a>$counter</a></li>";
}else{
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=$counter'>$counter</a></li>";
}
}
}
}
?>
<li class='' <?php if($page_no >= $total_no_of_pages){ echo "class='disabled'"; } ?>>
<a title="Next" class="page-link border border-danger text-danger" <?php if($page_no < $total_no_of_pages) { echo "href='?page_no=$next_page'"; } ?>><span class="fas fa-caret-right"></span></a>
</li>
<?php if($page_no < $total_no_of_pages){
echo "<li class=''><a href='?page_no=$total_no_of_pages' class='page-link text-danger border border-danger' title='Last'><span class='fas fa-caret-right'></span><span class='fas fa-caret-right'></span><span class='fas fa-caret-right'></span></a></li>";
} ?>
<!------------------------------ For the number of posts available -------------------------------->
</ul>
</div>
<?php
}else{
?>
<h5>All Collections</h5>
<hr>
<?php
if (isset($_GET['page_no']) && $_GET['page_no']!="") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}
$total_records_per_page = 10;
$offset = ($page_no-1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$adjacents = "2";
$result_count = mysqli_query($connect,"SELECT COUNT(*) As total_records FROM `products`");
$total_records = mysqli_fetch_array($result_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $total_records_per_page);
$second_last = $total_no_of_pages - 1; // total page minus 1
$result = mysqli_query($connect, "SELECT * FROM `products` ORDER BY id DESC LIMIT $offset, $total_records_per_page");
while ($row = mysqli_fetch_array($result)) {
$image = $row['image'];
$product = $row['product'];
$description = $row['description'];
$date = $row['date'];
$category = $row['category'];
$id_post = $row['id'];
?>
<!--------------------- PRODUCT DESIGN ----------->
<div class="row mx-0 group mb-3 shadow p-2 bg-white">
<div class="col-md-4 mt-4 p-3">
<img src="upload/<?php echo $row['image'] ?>" class="card-img">
</div>
<div class="col-md-8 pl-3">
<a href="collections.php?product_id=<?php echo $row['id']; ?>&&product=<?php echo $row['product']; ?>" class="nav-link">
<h3 class=" pt-3 mb-2">
<?php echo $row['product']; ?>
</h3>
</a>
<b class="mt-2 mb-5 d-block">
<?php if ($row['status']==1) {
?>
<span class="fas fa-check bg-danger rounded-circle text-light p-1"></span>
In Stock!
<?php }else{ ?>
<span class="fas fa-times bg-danger rounded-circle text-light p-1"></span>
Out of Stock!
<?php } ?>
</b>
<!-- <i class="mt-2 d-block"><?php echo substr($row['description'], 0, 120); ?>...</i> -->
<a href="collections.php?product_id=<?php echo $row['id']; ?>&&product=<?php echo $row['product']; ?>" class="text-uppercase">+ See full details here</a>
<br>
<div class="float-left mt-3">
<?php if ($row['old_price'] > 0): ?>
<h4 class="d-inline-block" style="text-decoration: line-through;">$<?php echo number_format($row['old_price'],2); ?></h4>
<?php endif ?>
<h2 class="d-inline-block text-danger" style="line-height: 25px;">$<?php echo number_format($row['price'],2); ?></h2>
</div>
<div class="float-right mt-3">
<a href="collections.php?product_id=<?php echo $row['id'] ?>&product=<?php echo $row['product'] ?>"><button class="btn btn-danger">View Product</button></a>
</div>
<div class="clearfix"></div>
<div >
</div>
</div>
</div>
<?php } ?>
<ul class="pagination">
<?php // if($page_no > 1){ echo "<li><a href='?page_no=1'>First Page</a></li>"; } ?>
<li class="border-danger border" <?php if($page_no <= 1){ echo "class='disable'"; } ?>>
<a class="page-link" <?php if($page_no > 1){ echo "href='?page_no=$previous_page'"; } ?>><span class="fas fa-caret-left text-danger " title="Previous"></span></a>
</li>
<?php
if ($total_no_of_pages <= 10){
for ($counter = 1; $counter <= $total_no_of_pages; $counter++){
if ($counter == $page_no) {
echo "<li class='active page-link text-light bg-danger border border-danger'><a>$counter</a></li>";
}else{
echo "<li><a href='?page_no=$counter' class='page-link text-danger border border-danger'>$counter</a></li>";
}
}
}
elseif($total_no_of_pages > 10){
if($page_no <= 4) {
for ($counter = 1; $counter < 8; $counter++){
if ($counter == $page_no) {
echo "<li class='active page-link text-light bg-danger border border-danger'><a>$counter</a></li>";
}else{
echo "<li><a href='?page_no=$counter' class='page-link text-danger border border-danger'>$counter</a></li>";
}
}
echo "<li class=' text-danger border border-danger'><a>...</a></li>";
echo "<li class='border border-danger'><a href='?page_no=$second_last' class='text-danger'>$second_last</a></li>";
echo "<li class='border border-danger'><a href='?page_no=$total_no_of_pages' class='text-danger'>$total_no_of_pages</a></li>";
}
elseif($page_no > 4 && $page_no < $total_no_of_pages - 4) {
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=1'>1</a></li>";
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=2'>2</a></li>";
echo "<li class='border border-danger'><a class='text-danger'>...</a></li>";
for ($counter = $page_no - $adjacents; $counter <= $page_no + $adjacents; $counter++) {
if ($counter == $page_no) {
echo "<li class='active text-light bg-danger border border-danger'><a>$counter</a></li>";
}else{
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=$counter'>$counter</a></li>";
}
}
echo "<li class='border border-danger' text-danger><a>...</a></li>";
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=$second_last'>$second_last</a></li>";
echo "<li class='border border-danger'><a class='text-danger-danger' href='?page_no=$total_no_of_pages'>$total_no_of_pages</a></li>";
}
else {
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=1'>1</a></li>";
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=2'>2</a></li>";
echo "<li class='border border-danger text-danger'><a>...</a></li>";
for ($counter = $total_no_of_pages - 6; $counter <= $total_no_of_pages; $counter++) {
if ($counter == $page_no) {
echo "<li class='active bg-danger text-light'><a>$counter</a></li>";
}else{
echo "<li class='border border-danger'><a class='text-danger' href='?page_no=$counter'>$counter</a></li>";
}
}
}
}
?>
<li class='' <?php if($page_no >= $total_no_of_pages){ echo "class='disabled'"; } ?>>
<a title="Next" class="page-link border border-danger text-danger" <?php if($page_no < $total_no_of_pages) { echo "href='?page_no=$next_page'"; } ?>><span class="fas fa-caret-right"></span></a>
</li>
<?php if($page_no < $total_no_of_pages){
echo "<li class=''><a href='?page_no=$total_no_of_pages' class='page-link text-danger border border-danger' title='Last'><span class='fas fa-caret-right'></span><span class='fas fa-caret-right'></span><span class='fas fa-caret-right'></span></a></li>";
} ?>
<!------------------------------ For the number of posts available -------------------------------->
</ul>
</div>
<?php } ?>
</div>
<?php include 'inc/footer.php'; ?>