-
Notifications
You must be signed in to change notification settings - Fork 0
/
search
235 lines (183 loc) · 8.15 KB
/
search
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
search.php---------------
<?php
include "lib/config.php";
include "lib/header.php";
?>
<!-- breadcrumb-area start -->
<div class="breadcrumb-area" style="height: 100px; margin-bottom: 50px;">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-12 text-center">
<h2 class="breadcrumb-title">Results for: <b><?php print $_GET['q'];?></b></h2>
<!-- breadcrumb-list start -->
</div>
</div>
</div>
</div>
<!-- breadcrumb-area end -->
<div class="container">
<div class="row">
<?php
include "lib/category.php";
?>
<div class="col-9">
<?php
$q = $_GET['q'];
$q = str_ireplace( [",", "+", ";", " AND ", "."] , " ", $q);
$sql = "SELECT * FROM `products`, `category`
WHERE `products`.`cid` = `category`.`cid` ";
$keywords = explode(" ", trim($q) ); // Egg Biriyani
foreach ($keywords as $keyword) {
$sql = $sql . " AND (
`products`.`name` LIKE '%$keyword%' OR
`products`.`details` LIKE '%$keyword%' OR
`category`.`cname` LIKE '%$keyword%'
) ";
}
if( isset($_GET['price']) ) {
if($_GET['price'] == "asc") {
$sql = $sql . " ORDER BY `products`.`price` ASC ";
$next_price = "desc";
} else {
$sql = $sql . " ORDER BY `products`.`price` DESC ";
$next_price = "asc";
}
}
else
$next_price = "";
$res = $db->query($sql);
$num = $res->num_rows;
print '<div class="row">
<div class="col">
<hr><h3>Found '.$num.' results for <b>'.$q.'</b></h3><hr>
</div>
</div>';
if($next_price=="" || $next_price=="asc")
print 'Sort by <a href = "search.php?q='.$q.'&price=asc">Price <img src = "./assets/images/price_down.png" width = 20></a>';
else
print 'Sort by <a href = "search.php?q='.$q.'&price=desc">Price <img src = "./assets/images/price_up.png" width = 20></a>';
print '<div class="row">';
while($row = $res->fetch_array()) {
displayProduct($row);
}
print '</div>';
function displayProduct($row)
{
print <<<EOF
<!-- start product div -->
<div class="col-4">
<div class="product">
<div class="thumb">
<a href="details.php?id=$row[id]" class="image">
<img src="$row[image]" style = "height: 200px;" />
<img class="hover-image"
src="$row[image]" alt="Product" />
</a>
</div>
<div class="content">
<span class="ratings">
<span class="rating-wrap">
<span class="star" style="width: 100%"></span>
</span>
<span class="rating-num d-none">( 5 Review )</span>
</span>
<h5 class="title"><a href="details.php?id=$row[id]">$row[name]
</a>
</h5>
<span class="price">
<span class="new">$row[price]</span>
<span class="old">$45.50</span>
</span>
</div>
</div>
</div>
<!-- end product div ---->
EOF;
}
?>
</div>
</div>
</div>
<?php
include "lib/footer.php";
?>
lib/config.php-------------------
<?php
session_start();
date_default_timezone_set("Asia/Kolkata");
$db = new MySQLi("localhost", "root", "", "4th project");
foreach ($_POST as $key => $value) {
if( !is_array($value) )
$_POST[$key] = addslashes($value);
}
foreach ($_GET as $key => $value) {
$_GET[$key] = addslashes($value);
}
lib header.php-----------------------
<!DOCTYPE html>
<html lang="zxx">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta name="robots" content="index, follow" />
<title>Mioca - Handmade Goods eCommerce HTML Template</title>
<meta name="description" content="Mioca - Handmade Goods eCommerce HTML Template" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- Add site Favicon -->
<link rel="shortcut icon" href="assets/images/favicon/favicon.ico" type="image/png">
<!-- vendor css (Icon Font) -->
<link rel="stylesheet" href="assets/css/vendor/bootstrap.bundle.min.css" />
<link rel="stylesheet" href="assets/css/vendor/pe-icon-7-stroke.css" />
<link rel="stylesheet" href="assets/css/vendor/font.awesome.css" />
<!-- plugins css (All Plugins Files) -->
<link rel="stylesheet" href="assets/css/plugins/animate.css" />
<link rel="stylesheet" href="assets/css/plugins/swiper-bundle.min.css" />
<link rel="stylesheet" href="assets/css/plugins/jquery-ui.min.css" />
<link rel="stylesheet" href="assets/css/plugins/nice-select.css" />
<link rel="stylesheet" href="assets/css/plugins/venobox.css" />
<!-- Use the minified version files listed below for better performance and remove the files listed above -->
<!-- <link rel="stylesheet" href="assets/css/vendor/vendor.min.css" />
<link rel="stylesheet" href="assets/css/plugins/plugins.min.css" />
<link rel="stylesheet" href="assets/css/style.min.css"> -->
<!-- Main Style -->
<link rel="stylesheet" href="assets/css/style.css" />
</head>
<body>
<!-- Header Area Start -->
<header>
<div class="header-main sticky-nav ">
<div class="container position-relative">
<div class="row">
<div class="col-auto align-self-center">
<div class="header-logo">
<a href="index.php"><img src="assets/images/logo/logo.png" alt="Site Logo" /></a>
</div>
</div>
<div class="col align-self-center d-none d-lg-block">
<table border="0" align="right">
<tr>
<td>
<div class="main-menu">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="view_cart.php">View Cart</a></li>
<li><a href="checkout.php">Checkout</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div>
</td>
<td>
<form method="GET" action="search.php">
<input type="text" name="q" style="width: 180px; float: left; margin-left: 40px; margin-right: 10px; background: white; border: 1px solid silver; border-radius: 6px;" placeholder="Search Products">
<input class="btn btn-danger" type="submit" value="Go" style="width: 40px; ">
</form>
</td>
</tr>
</table>
</div>
<!-- Header Action Start -->
</div>
</div>
</div>
</header>
----------------------------END-------------------------