-
Notifications
You must be signed in to change notification settings - Fork 0
/
search-result.php
271 lines (255 loc) · 14.1 KB
/
search-result.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
<?php require_once('header.php'); ?>
<?php
if(!isset($_REQUEST['search_text'])) {
header('location: index.php');
exit;
} else {
if($_REQUEST['search_text']=='') {
header('location: index.php');
exit;
}
}
?>
<?php
$statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$banner_search = $row['banner_search'];
}
?>
<div class="page-banner" style="background-image: url(assets/uploads/<?php echo $banner_search; ?>);">
<div class="overlay"></div>
<div class="inner">
<h1>
Search By:
<?php
$search_text = strip_tags($_REQUEST['search_text']);
echo $search_text;
?>
</h1>
</div>
</div>
<div class="page">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="product product-cat">
<div class="row">
<?php
$search_text = '%'.$search_text.'%';
?>
<?php
/* ===================== Pagination Code Starts ================== */
$adjacents = 5;
$statement = $pdo->prepare("SELECT * FROM tbl_product WHERE p_is_active=? AND p_name LIKE ?");
$statement->execute(array(1,$search_text));
$total_pages = $statement->rowCount();
$targetpage = BASE_URL.'search-result.php?search_text='.$_REQUEST['search_text']; //your file name (the name of this file)
$limit = 12; //how many items to show per page
$page = @$_GET['page'];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0;
$statement = $pdo->prepare("SELECT * FROM tbl_product WHERE p_is_active=? AND p_name LIKE ? LIMIT $start, $limit");
$statement->execute(array(1,$search_text));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
if ($page > 1)
$pagination.= "<a href=\"$targetpage&page=$prev\">« previous</a>";
else
$pagination.= "<span class=\"disabled\">« previous</span>";
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";
}
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage&page=1\">1</a>";
$pagination.= "<a href=\"$targetpage&page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";
}
else
{
$pagination.= "<a href=\"$targetpage&page=1\">1</a>";
$pagination.= "<a href=\"$targetpage&page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";
}
}
}
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage&page=$next\">next »</a>";
else
$pagination.= "<span class=\"disabled\">next »</span>";
$pagination.= "</div>\n";
}
/* ===================== Pagination Code Ends ================== */
?>
<?php
if(!$total_pages):
echo '<span style="color:red;font-size:18px;">No result found</span>';
else:
foreach ($result as $row) {
?>
<div class="col-md-3 item item-search-result">
<div class="inner">
<div class="thumb">
<div class="photo" style="background-image:url(assets/uploads/<?php echo $row['p_featured_photo']; ?>);"></div>
<div class="overlay"></div>
</div>
<div class="text">
<h3><a href="product.php?id=<?php echo $row['p_id']; ?>"><?php echo $row['p_name']; ?></a></h3>
<h4>
$<?php echo $row['p_current_price']; ?>
<?php if($row['p_old_price'] != ''): ?>
<del>
$<?php echo $row['p_old_price']; ?>
</del>
<?php endif; ?>
</h4>
<div class="rating">
<?php
$t_rating = 0;
$statement1 = $pdo->prepare("SELECT * FROM tbl_rating WHERE p_id=?");
$statement1->execute(array($row['p_id']));
$tot_rating = $statement1->rowCount();
if($tot_rating == 0) {
$avg_rating = 0;
} else {
$result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
foreach ($result1 as $row1) {
$t_rating = $t_rating + $row1['rating'];
}
$avg_rating = $t_rating / $tot_rating;
}
?>
<?php
if($avg_rating == 0) {
echo '';
}
elseif($avg_rating == 1.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
<i class="fa fa-star-o"></i>
<i class="fa fa-star-o"></i>
<i class="fa fa-star-o"></i>
';
}
elseif($avg_rating == 2.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
<i class="fa fa-star-o"></i>
<i class="fa fa-star-o"></i>
';
}
elseif($avg_rating == 3.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
<i class="fa fa-star-o"></i>
';
}
elseif($avg_rating == 4.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
';
}
else {
for($i=1;$i<=5;$i++) {
?>
<?php if($i>$avg_rating): ?>
<i class="fa fa-star-o"></i>
<?php else: ?>
<i class="fa fa-star"></i>
<?php endif; ?>
<?php
}
}
?>
</div>
<?php if($row['p_qty'] == 0): ?>
<div class="out-of-stock">
<div class="inner">
Out Of Stock
</div>
</div>
<?php else: ?>
<p><a href="product.php?id=<?php echo $row['p_id']; ?>">Add to Cart</a></p>
<?php endif; ?>
</div>
</div>
</div>
<?php
}
?>
<div class="clear"></div>
<div class="pagination">
<?php
echo $pagination;
?>
</div>
<?php
endif;
?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>