-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsearch.php
239 lines (176 loc) · 7.71 KB
/
search.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
<?php
include_once('./includes/headerNav.php');
include "includes/config.php";
?>
<div class="overlay" data-overlay></div>
<!--
- HEADER
-->
<header>
<!-- top head action, search etc in php -->
<?php require_once './includes/topheadactions.php'; ?>
<!-- mobile nav in php -->
<?php require_once './includes/mobilenav.php'; ?>
</header>
<!--
- MAIN
-->
<main>
<div class="product-container">
<div class="container">
<!--
- SIDEBAR
-->
<!-- CATEGORY SIDE BAR MOBILE MENU -->
<?php require_once './includes/categorysidebar.php'; ?>
<!-- ############################# -->
<div class="product-box">
<!-- get id and url for each category and display its dat from table her in this secton -->
<div class="product-main">
<h2 class="title">
Search:
<?php
// Get Item name searching for
if(isset($_POST['search']))
{
echo $_POST['search'];
}
?>
</h2>
<div class="product-grid">
<!-- display data from table new products -->
<?php
//Very important SEO friendly code generated by myself (practices)
if(isset($_POST['submit']) AND !(empty($_POST['search'])) OR isset($_POST['catag'])) {
if(isset($_GET['catag'])) {
$seacrh_term = mysqli_real_escape_string($conn, $_GET['catag']);
} else {
$seacrh_term = mysqli_real_escape_string($conn, $_POST['search']);
}
if (isset($_GET['page'])){
$page = $_GET['page'];
} else {
$page = 1;
}
// define how much data to show in a page from database
$limit = 8;
// define from which row to start extracting data from database
$offset = ($page - 1) * $limit;
//making search_term string to array each value separated by space
$search_term_array = explode(" ",$seacrh_term);
// Loop over each item
for($search=0; $search<sizeof($search_term_array); $search++){
$array_length = sizeof($search_term_array);
if($array_length > 1) {
$search_query = "SELECT * FROM products WHERE products.product_title LIKE '%{$search_term_array[$search]}%' AND products.product_catag LIKE '%{$search_term_array[$search+1]}%' ORDER BY products.product_id DESC LIMIT {$offset},{$limit}";
}
if($array_length == 1) {
$search_query = "SELECT * FROM products WHERE products.product_title LIKE '%{$search_term_array[$search]}%' OR products.product_catag LIKE '%{$search_term_array[$search]}%' ORDER BY products.product_id DESC LIMIT {$offset},{$limit}";
}
break;
}
// Execute search query
$search_result = $conn->query($search_query);
$new_product_counter = 1;
// Query used earlier
// $search_query = "SELECT * FROM PRODUCT WHERE product.name LIKE '%$get_seach_value%' ";
// $run_search = mysqli_query($connect,$search_query);
if($search_result->num_rows > 0) {
while ($row = mysqli_fetch_assoc($search_result)) {
?>
<!-- display all category products -->
<div class="showcase">
<div class="showcase-banner">
<img src="./admin/upload/<?php
echo $row['product_img']
?>" alt="Mens Winter Leathers Jackets" width="300" class="product-img default" />
<img src="./admin/upload/<?php
echo $row['product_img']
?>" alt="search result images" width="300" class="product-img hover" />
<!-- Applying coditions on dicount and sale tags -->
<!-- -->
<div class="showcase-actions">
<button class="btn-action">
<ion-icon name="heart-outline"></ion-icon>
</button>
<button class="btn-action">
<ion-icon name="eye-outline">
</ion-icon>
</button>
<button class="btn-action">
<ion-icon name="repeat-outline"></ion-icon>
</button>
<button class="btn-action">
<ion-icon name="bag-add-outline"></ion-icon>
</button>
</div>
</div>
<div class="showcase-content">
<a href="./viewdetail.php?id=<?php echo $row['product_id'] ?>&category=<?php $row['category_id'] ?>" class="showcase-category">
<?php echo $row['product_title'] ?>
</a>
<a href="./viewdetail.php?id=<?php echo $row['product_id'] ?>&category=<?php $row['category_id'] ?>">
<h3 class="showcase-title">
<?php echo $row['product_desc'] ?>
</h3>
</a>
<div class="showcase-rating">
<ion-icon name="star"></ion-icon>
<ion-icon name="star"></ion-icon>
<ion-icon name="star"></ion-icon>
<ion-icon name="star"></ion-icon>
<ion-icon name="star"></ion-icon>
</div>
<div class="price-box">
<p class="price">
$<?php echo $row['discounted_price'] ?>
</p>
<del>
$<?php echo $row['product_price'] ?>
</del>
</div>
</div>
</div>
<?php
$new_product_counter = $new_product_counter + 1;
}} else {
echo "<h4 style='color:red; margin-left:8%;border:1px solid aliceblue'>"."No record found"."</h4>";
}
$conn->close();
?>
<!-- -->
</div>
</div>
</div>
</div>
</div>
<!--Pagination-->
<div class="pag-cont-search">
<?php
include "includes/config.php";
// Pagination btn using php with active effects
$sql1 = "SELECT * FROM products";
$result1 = mysqli_query($conn, $sql1) or die("Query Failed.");
if(mysqli_num_rows($result1) > 0){
$total_products = mysqli_num_rows($search_result);
$total_page = ceil($total_products / $limit);
echo "<div class='pagination'>";
for($i=1; $i<=$total_page; $i++){
//important this is for active effects that denote in which page you are in current position
if($page==$i){
$active = "active";
}else{
$active = "";
}
echo "<a href='search.php?page={$i}' class='{$active}'>".$i."</a>";
}
}
echo "</div>";
} //main if
else {
echo "<h4 style='color:red; margin-left:8%;border:1px solid aliceblue'>"."ERR_Insert on Search"."</h4>";
}
?>
</div>
</main>
<?php require_once './includes/footer.php'; ?>