-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.php
67 lines (64 loc) · 2.15 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
<?php
# IF page is accessed not via post, redirect and kill the script
if(!$_POST){
header('Location: index.php');
die();
}
require_once("core/init.php");
include("includes/head.php");
include("includes/navigation.php");
include("includes/headerpartial.php");
include("includes/leftbar.php");
$sql = "SELECT * FROM products";
$cat_id = (($_POST['cat'] != '')?sanitize($_POST['cat']):'');
if($cat_id == ''){
$sql .= " WHERE archived = 0";
} else {
$sql .= " WHERE categories = '$cat_id' AND archived = 0";
}
$price_sort = (($_POST['price_sort'] != '')?sanitize($_POST['price_sort']):'');
$min_price = (($_POST['min_price'] != '')?sanitize($_POST['min_price']):'');
$max_price = (($_POST['max_price'] != '')?sanitize($_POST['max_price']):'');
$brand = (($_POST['brand'] != '')?sanitize($_POST['brand']):'');
if($min_price != ''){
$sql .= " AND price >= '$min_price'";
}
if($max_price != ''){
$sql .= " AND price <= '$max_price'";
}
if($brand != ''){
$sql .= " AND brand = '$brand'";
}
if($price_sort == 'low'){
$sql .= " ORDER BY price";
}
if($price_sort == 'high'){
$sql .= " ORDER BY price DESC";
}
$productQ = $db->query($sql);
$category = get_category($cat_id);
?>
<!--Main Content-->
<div class="col-md-8">
<div class="row">
<?php if($cat_id != ''): ?>
<h2 class="text-center"><?=$category['parent'].' '.$category['child'];?> - Search Results</h2>
<?php else: ?>
<h2 class="text-center">Search Results</h2>
<?php endif; ?>
<?php while($product = mysqli_fetch_assoc($productQ)) : ?>
<div class="col-md-3 text-center">
<h4><?= $product['title']; ?></h4>
<?php $photos = explode(',',$product['image']); ?>
<img src="<?= $photos[0]; ?>" alt="<?= $product['title']; ?>" class="img-thumb"/>
<p class="list-price text-danger">List Price: <s>£<?= $product['list_price']; ?></s></p>
<p class="price">Our Price: £<?= $product['price']; ?></p>
<button type="button" class="btn btn-sm btn-success" onclick="detailsmodal(<?=$product['id'];?>)">Details</button>
</div>
<?php endwhile; ?>
</div>
</div>
<?php
include("includes/rightbar.php");
include("includes/footer.php");
?>