-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvancedSearchProcess.php
More file actions
166 lines (108 loc) · 4.99 KB
/
advancedSearchProcess.php
File metadata and controls
166 lines (108 loc) · 4.99 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
<?php
include "connection.php";
$search_txt = $_POST["t"];
$category = $_POST["c1"];
$price_from = $_POST["pf"];
$price_to = $_POST["pt"];
$page = $_POST["page"];
$query = "SELECT * FROM `product`";
$status = 0;
if (!empty($search_txt)) {
$query .= " WHERE `title` LIKE '%" . $search_txt . "%' ";
$status = 1;
}
if ($category != 0 && $status == 0) { //status = 0 defines there is no texts in search_text
$query .= " WHERE `category_cat_id` = '" . $category . "' ";
} else if ($category != 0 && $status != 0) {
$query .= " AND `category_cat_id` = '" . $category . "' ";
} else {
$pageno;
if ("0" != $_POST["page"]) {
$pageno = $_POST["page"];
} else {
$pageno = 1;
}
$product_rs = Database::search($query);
$product_num = $product_rs->num_rows;
$products_per_page = 20;
$num_of_pages = ceil($product_num / $products_per_page);
$page_results = ($pageno - 1) * $products_per_page;
$selected_rs = Database::search($query . " LIMIT " . $products_per_page . " OFFSET " . $page_results . "");
$selected_num = $selected_rs->num_rows;
for ($x = 0; $x < $selected_num; $x++) {
$selected_data = $selected_rs->fetch_assoc();
?>
<div class="col p-3">
<div class="card custom-card bg-secondary-subtle" style="width: 25rem;">
<div class="product-img">
<?php
$img_rs = Database::search("SELECT * FROM `product_img` WHERE `product_id` = '" . $selected_data["id"] . "' ");
$img_num = $img_rs->num_rows;
$img_data = $img_rs->fetch_assoc();
if ($img_num > 0) {
?>
<img src="<?php echo $img_data["img_path"]; ?>" alt="">
<?php
} else {
//default img
?>
<img src="img/banner/pngwing.com (1).png" alt="">
<?php
}
?>
</div>
<div class="text-center">
<strong><?php echo $selected_data["title"]; ?></strong>
</div>
<div class="text-center mb-1">
<p class="card-title"><?php echo $selected_data["price"]; ?></p>
<?php
if ($selected_data["qty"] > 0) {
?>
<span class="card-text text-warning fw-bold">In Stock</span>
<br>
<span class="card-text text-success fw-bold"><?php echo $selected_data["qty"]; ?> Items Available</span>
<a href="#" class="cart-btn text-decoration-none" onclick="addToCart('<?php echo $selected_data['id']; ?>','<?php echo $selected_data['qty']; ?>');">
<i class='fa fa-shopping-cart text-dark'></i>Add to cart
</a>
<a href='singleProductView.php?id=<?php echo $selected_data["id"]; ?>' class="buy-button mt-2 d-grid"><i class='bx bxs-shopping-bag'></i>Buy Now</a>
<?php
} else {
?>
<span class="card-text text-danger fw-bold">Out Of Stock</span>
<br>
<span class="card-text text-danger fw-bold">00 Items Available</span>
<a href="#" class="cart-btn text-decoration-none">
<i class='fa fa-shopping-cart text-dark'></i>Add to cart
</a>
<a href="" class="buy-button btn btn-danger mt-2 d-grid disabled">Buy Now</a>
<?php
}
?>
</div>
<?php
if (isset($_SESSION["u"])) {
$watchlist_rs = Database::search("SELECT * FROM `watchlist` WHERE `users_email` = '" . $_SESSION["u"]["email"] . "' AND
`product_id` = '" . $product_data["id"] . "'");
$watchlist_num = $watchlist_rs->num_rows;
if ($watchlist_num == 1) {
?>
<a href="#" class="like-btn text-danger" onclick="addToWatchlist(<?php echo $selected_data['id']; ?>);">
<i id="heart<?php echo $selected_data['id']; ?>" class="bi bi-heart-fill"></i>
</a>
<?php
} else {
?>
<a href="#" class="like-btn text-dark" onclick="addToWatchlist(<?php echo $selected_data['id']; ?>);">
<i id="heart<?php echo $selected_data['id']; ?>" class="bi bi-heart-fill"></i>
</a>
<?php
}
}
?>
</div>
</div>
<?php
}
}
?>