-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
83 lines (61 loc) · 2.3 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
<?php
include "header.php";
include_once "Products/products.php";
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['searchString'])){
$_SESSION['searchString'] = $_POST['searchString'];
$stmt = $DBH->query("select p.id, p.name, p.description, p.image_location, p.price, p.date_added, pr.percentage,pr.expiration_date
from products p
left join promotions pr on pr.product_id = p.id and pr.expiration_date >= CURDATE()
where name like '%" . $_SESSION['searchString'] . "%'
or product_category like '%" . $_SESSION['searchString'] . "%'
or article_category like '%" . $_SESSION['searchString'] . "%'
or gender_category like '%" . $_SESSION['searchString'] . "%'
order by p.date_added desc");
$stmt_count_sql = $DBH->query("select count(*) from products where name like '%" . $_SESSION['searchString'] . "%'
or product_category like '%" . $_SESSION['searchString'] . "%'
or article_category like '%" . $_SESSION['searchString'] . "%'
or gender_category like '%" . $_SESSION['searchString'] . "'");
}
}
if(!isset($stmt)){
$stmt = null;
}
if(!isset($_SESSION['searchString'])){
$_SESSION['searchString'] = null;
}
$per_row = 4;
?>
<div class="container-fluid">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<table class = "table table-product">
<?php
//$count1 = $stmt->fetch();
$count1 = $stmt_count_sql->fetch();
$i = 0;
echo "<br/>\n";
if($stmt->rowCount() > 0){
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<td>';
// If the item is added in inventory within last 7 days
if (strtotime($row['date_added']) > strtotime('-7 days')) {
echo displayNewProductIcon();
}
echo displayProducts($row['id'], $row['image_location'], $row['name']);
echo displayPrice($row['price'], $row['percentage'], $row['expiration_date']);
echo "<br/><br/>\n";
echo '</td>';
// display pants in 4 columns
if (++$i % $per_row == 0 && $i >0 && $i < $count1) {
echo '<tr></tr>';
}
}
}else{
echo "<p>That search did not return any results.</p>";
}
?>
</table>
</div>
</div>
</div>