-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.php
139 lines (116 loc) · 5.65 KB
/
results.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
<?php
include('config/db.php');
if (isset($_GET['search']) && empty($_GET['search'])) {
header('location: index.php');
}
if (isset($_GET['cat'])) {
$page_title = $_GET['cat'];
}
if (isset($_GET['search'])) {
$page_title = "Results for: " . $_GET['search'];
}
$message = "";
?>
<?php
include('includes/head.php');
?>
<!-- Page Content -->
<div class="container" style="text-align: left; max-width: 1500px">
<div class="row">
<div class="col-lg-3">
<?php
include('includes/neon_shop_name.php');
?>
<div class="list-group">
<a href="results.php?cat=laptop" class="list-group-item">Laptop</a>
<a href="results.php?cat=mobile" class="list-group-item">Phone</a>
<a href="results.php?cat=tablet" class="list-group-item">Tablet</a>
<a href="results.php?cat=smartWatch" class="list-group-item">Smart Watch</a>
</div>
</div>
<div class="col-lg-9">
<div class="row mt-5">
<?php
if (isset($_GET)) {
if (isset($_GET['cat'])) {
$cat = trim($_GET['cat']);
$query = "SELECT * FROM t_product WHERE p_category=:category";
$stmt = $pdo->prepare($query);
$exec = $stmt->execute(['category' => $cat]);
}
if (isset($_GET['search'])) {
$searchInput = trim($_GET['search']);
$query = "SELECT * FROM t_product WHERE p_name LIKE :searchInput
UNION
SELECT * FROM t_product WHERE p_category LIKE :searchInput
UNION
SELECT * FROM t_product WHERE p_description LIKE :searchInput
UNION
SELECT * FROM t_product WHERE p_brand LIKE :searchInput
";
$stmt = $pdo->prepare($query);
$exec = $stmt->execute(['searchInput' => "%" . $searchInput . "%"]);
}
if (isset($_GET['cat']) || isset($_GET['search'])) {
if ($exec) {
while ($productRow = $stmt->fetch()) {
$id = $productRow['p_id'];
$name = $productRow['p_name'];
$category = $productRow['p_category'];
$img = $productRow['p_image'];
$price = $productRow['p_price'];
$desc = $productRow['p_description'];
$color = $productRow['p_color'];
$size = $productRow['p_size'];
$isAvailable = $productRow['p_isAvailable'];
$count = $productRow['p_count'];
$weight = $productRow['p_weight'];
$brand = $productRow['p_brand'];
$desc = substr($desc, 0, 150);
echo " <div class='col-lg-4 col-md-6 mb-4'>
<div class='card'>
<a href='single_product.php?id={$id}'><img class='card-img-top' src='assets/img/products/{$img}' alt='$name' style='height: 300px'></a>
<div class='card-body'>
<h4 class='card-title'>
<a href='single_product.php?id={$id}'>$name</a>
</h4>
<h5>$$price</h5>
<p class='card-text'>$desc ...
<a href='single_product.php?id={$id}' class='btn btn-link'>Read more</a>
</p>
</div>
<div class='card-footer d-flex justify-content-between'>
<small class='text-muted align-self-end'>★ ★ ★ ★ ☆</small>
<form action='user/cart.php' method='post'>
<input type='hidden' name='product_id' value='{$id}'>
<button class='btn btn-outline-primary' type='submit' name='addToCartSubmit'>Add to Cart <i class='fa fa-shopping-cart'></i></button>
</form>
</div>
</div>
</div>";
}
}
} else {
echo "<div class='alert alert-danger text-center'>No Result Found!</div>";
}
}
?>
</div>
<?php
if (isset($_GET['cat']) || isset($_GET['search'])) {
if ($stmt->rowCount() <= 0) {
if (isset($_GET['cat'])) {
echo "<div class='alert alert-info text-center'>No Result Found for \" $_GET[cat] \"</div>";
} else if (isset($_GET['search'])) {
echo "<div class='alert alert-info text-center'>No Result Found for \" $_GET[search] \"</div>";
}
}
}
?>
</div>
</div>
</div>
<!-- /.row -->
<?php
include('includes/tail.php');
?>