-
Notifications
You must be signed in to change notification settings - Fork 4
/
product.php
187 lines (150 loc) · 7.34 KB
/
product.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
<?php include('include/header.php');
if(isset($_GET['page'])){
$page_id = $_GET['page'];
}
else{
$page_id = 1;
}
$required_pro = 12;
$query = "SELECT * FROM furniture_product Where status = 'publish' ORDER BY pid";
$run = mysqli_query($con,$query);
$count_rows = mysqli_num_rows($run);
$pages = ceil($count_rows / $required_pro);
$product_start = ($page_id - 1) * $required_pro;
if(isset($_SESSION['id'])){
$custid = $_SESSION['id'];
if(isset($_GET['cart_id'])){
$p_id = $_GET['cart_id'];
$sel_cart = "SELECT * FROM cart WHERE cust_id = $custid and product_id = $p_id ";
$run_cart = mysqli_query($con,$sel_cart);
if(mysqli_num_rows($run_cart) == 0){
$cart_query = "INSERT INTO `cart`(`cust_id`, `product_id`,quantity) VALUES ($custid,$p_id,1)";
if(mysqli_query($con,$cart_query)){
header("location:product.php");
}
}
if(mysqli_num_rows($run_cart) > 0){
while($row = mysqli_fetch_array($run_cart)){
$exist_pro_id = $row['product_id'];
if($p_id == $exist_pro_id){
$error="<script>alert('⚠️ This product is already in your cart '); </script>";
}
}
}
}
}
else if(!isset($_SESSION['email'])){
echo "<script> function a(){alert('⚠️ Login is required to add this product into cart');}</script>";
}
?>
<div class="jumbotron">
<h2 class="text-center mt-5">Choose Products</h2>
</div>
<div class="container mt-5">
<div class="row">
<div class="col-md-3 col-12">
<div class="list-group">
<a href='product.php' class='list-group-item'><i class='fal fa-home ml-2'></i> Products </a>
<?php
$cat_query = "SELECT * FROM categories ORDER BY id ASC";
$cat_run = mysqli_query($con,$cat_query);
if(mysqli_num_rows($cat_run) > 0){
While($cat_row = mysqli_fetch_array($cat_run)){
$cid = $cat_row['id'];
$cat_name = ucfirst($cat_row['category']);
$font = $cat_row['fontawesome-icon'];
echo " <a href='product.php?cat_id=$cid' class='list-group-item'><i class='fal $font ml-2'></i> $cat_name </a>";
}
}
else{
echo " <a class='list-group-item'> No Category </a>";
}
?>
</div>
</div>
<div class="col-md-9 col-12">
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6">
<form method="post">
<div class="input-group">
<input type="text" class="form-control" name="search" placeholder="Search Products">
<div class="input-group-append">
<input class="btn btn-primary rounded-left" type="submit" name="sear_submit" vlaue="Search">
</div>
</div>
</form>
</div>
</div>
<?php
if(isset($msg)){
echo $msg;
}
else if(isset($error)){
echo $error;
}
?>
<!----Product list-->
<div class="row">
<?php
if(isset($_GET['cat_id'])){
$catid = $_GET['cat_id'];
$cat_query = "SELECT * FROM categories WHERE id=$catid ORDER BY id ASC";
$run = mysqli_query($con,$cat_query);
$row = mysqli_fetch_array($run);
$catname=$row['category'];
$p_query = "SELECT * FROM furniture_product WHERE category=$catid ORDER BY pid DESC LIMIT $product_start,$required_pro";
} else if(isset($_POST['sear_submit'])){
$search = $_POST['search'];
$p_query = "SELECT * FROM furniture_product WHERE title LIKE '%$search%' ";
}
else{
$p_query = "SELECT * FROM furniture_product WHERE status='publish' ORDER BY pid DESC LIMIT $product_start,$required_pro";
}
$p_run = mysqli_query($con,$p_query);
if(mysqli_num_rows($p_run) > 0 ){
while($p_row = mysqli_fetch_array($p_run)){
$pid = $p_row['pid'];
$ptitle = $p_row['title'];
$pcat = $p_row['category'];
$p_price = $p_row['price'];
$size = $p_row['size'];
$img1 = $p_row['image'];
?>
<div class="col-md-4 mt-4">
<img src="img/<?php echo $img1; ?>" class="hover-effect" width="100%" height="190px">
<div class="text-center mt-3">
<h5 title="<?php echo $ptitle; ?>"><?php echo substr($ptitle,0,20); ?>...</h5>
<h6>Rs. <?php echo $p_price; ?></h6>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 col-12 text-center">
<a href="product.php?cart_id=<?php echo $pid;?>" type="submit" onclick="a()" class="btn btn-primary btn-sm hover-effect">
<i class="far fa-shopping-cart"></i>
</a>
<a href="product-detail.php?product_id=<?php echo $pid;?>" class="btn btn-default btn-sm hover-effect text-dark" >
<i class="far fa-info-circle"></i> View Details
</a>
</div>
</div>
</div>
<?php
}
}
else{
echo "<h3 class='text-center'> Products Are Not Available Yet </h3>";
}
?>
</div>
<!--end product list-->
<!---Pagination-->
<ul class="pagination pagination-md mt-5">
<?php for($i=1; $i <= $pages; $i++ ){
echo "<li class='page-item ".($i == $page_id ? ' active ' : '')."'><a class='page-link' href='product.php?page=$i'>$i</a></li>";
}?>
</ul>
<!---end pagination-->
</div>
</div>
</div>
<?php include('include/footer.php'); ?>