-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
138 lines (115 loc) · 4.44 KB
/
category.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
<?php
session_start();
if (! isset($_SESSION['logged_in'])) {
$nav = 'includes/nav.php';
} else {
$nav = 'includes/navconnected.php';
$idsess = $_SESSION['id'];
}
if (! isset($_GET['id'])) {
header('Location: index');
}
$id_category = $_GET['id'];
require 'includes/header.php';
require $nav;
?>
<div class="container-fluid product-page">
<div class="container current-page">
<nav>
<div class="nav-wrapper">
<div class="col s12">
<a href="index" class="breadcrumb">Home</a> <a
href="category.php?id=<?= $id_category; ?>" class="breadcrumb">Category</a>
</div>
</div>
</nav>
</div>
</div>
<div class="container-fluid category-page">
<div class="row">
<div class="col s12 m2 center-align cat">
<div class="collection card">
<?php
include 'db.php';
// get categories
$querycategory = "SELECT id, name FROM category";
$total = $connection->query($querycategory);
if ($total->num_rows > 0) {
// output data of each row
while ($rowcategory = $total->fetch_assoc()) {
$id_categorydb = $rowcategory['id'];
$name_category = $rowcategory['name'];
?>
<a href="category.php?id=<?= $id_categorydb; ?>"
class='collection-item <?php if($id_categorydb == $id_category) {echo"active";} ?>'><?= $name_category; ?></a>
<?php }} ?>
</div>
</div>
<div class="col s12 m10 ">
<div class="container content">
<div class="center-align">
<button class="button-rounded btn-large waves-effect waves-light">Products</button>
</div>
<div class="row">
<?php
// get products
// pages links
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$perpage = isset($_GET['per-page']) && $_GET['per-page'] <= 16 ? (int) $_GET['per-page'] : 16;
$start = ($page > 1) ? ($page * $perpage) - $perpage : 0;
$queryproduct = "SELECT SQL_CALC_FOUND_ROWS id, name, price, id_picture, thumbnail FROM product WHERE id_category = '{$id_category}' ORDER BY id DESC LIMIT {$start}, 16";
$result = $connection->query($queryproduct);
// pages
$total = $connection->query("SELECT FOUND_ROWS() as total")->fetch_assoc()['total'];
$pages = ceil($total / $perpage);
if ($result->num_rows > 0) {
// output data of each row
while ($rowproduct = $result->fetch_assoc()) {
$id_product = $rowproduct['id'];
$name_product = $rowproduct['name'];
$price_product = $rowproduct['price'];
$id_pic = $rowproduct['id_picture'];
$thumbnail_product = $rowproduct['thumbnail'];
?>
<div class="col s12 m4">
<div class="card hoverable animated slideInUp wow">
<div class="card-image">
<a href="product.php?id=<?= $id_product; ?>"> <img
src="products/<?= $thumbnail_product; ?>"></a> <span
class="card-title grey-text"><?= $name_product; ?></span> <a
href="product.php?id=<?= $id_product; ?>"
class="btn-floating halfway-fab waves-effect waves-light right"><i
class="material-icons">add</i></a>
</div>
<div class="card-action">
<div class="container-fluid">
<h5 class="white-text"><?= $price_product; ?> $</h5>
</div>
</div>
</div>
</div>
<?php }} ?>
</div>
<div class="center-align animated slideInUp wow">
<ul class="pagination <?php if($total<15){echo "hide";} ?>">
<li class="<?php if($page == 1){echo 'hide';} ?>"><a
href="?page=<?php echo $page-1; ?>&per-page=15"><i
class="material-icons">chevron_left</i></a></li>
<?php for ($x=1; $x <= $pages; $x++) : $y = $x;?>
<li
class="waves-effect pagina <?php if($page === $x){echo 'active';} elseif($page < ($x +1) OR $page > ($x +1)){echo'hide';} ?>"><a
href="?page=<?php echo $x; ?>&per-page=15"><?php echo $x; ?></a></li>
<?php endfor; ?>
<li class="<?php if($page == $y){echo 'hide';} ?>"><a
href="?page=<?php echo $page+1; ?>&per-page=15"><i
class="material-icons">chevron_right</i></a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php
require 'includes/secondfooter.php';
require 'includes/footer.php';
?>