-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
182 lines (158 loc) · 6.78 KB
/
search.php
File metadata and controls
182 lines (158 loc) · 6.78 KB
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
<?php
// Include database connection and header
include("connection.php");
include("header.php");
// Check if search term is provided
if (!isset($_GET['query']) || empty(trim($_GET['query']))) {
echo "<h2>Please enter a search term.</h2>";
include("footer.php");
exit();
}
// Get and sanitize the search term
$search_term = trim($_GET['query']);
$search_term = mysqli_real_escape_string($conn, $search_term); // Prevent SQL injection
// Fetch products matching the search term with category details
$sql = "SELECT category.category_name, product.* FROM category JOIN product ON category.c_id = product.c_id WHERE product.product_name LIKE '%$search_term%' OR category.category_name LIKE '%$search_term%' ";
$result = mysqli_query($conn, $sql);
// Calculate expected delivery date (current date + 5 days)
$expected_delivery_date = date('d M Y', strtotime('+5 days'));
?>
<style>
.search_product_card {
background-color: white;
width: 80%;
margin: 0 auto;
height: auto;
box-shadow: -1px 1px 26px -5px #c5c5c5;
border-radius: 10px;
margin-bottom: 40px;
padding: 0;
display: flex;
align-items: center;
position: relative;
}
.search_product_image {
padding: 30px;
flex: 1;
text-align: center;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.search_product_image img {
max-width: 100%;
max-height: 200px;
border-radius: 10px;
}
.search_product_description {
flex: 2;
padding: 0 20px;
}
.search_product_price {
flex: 1;
text-align: center;
font-size: 18px;
font-weight: bold;
color: #333;
height: 295px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
.search_result_heading {
margin-bottom: 30px;
}
.delivery_date {
font-size: 14px;
color: #009f00;
margin-top: 10px;
font-family: 'Poppins';
font-weight: 500;
}
/* Make card clickable but exclude wishlist */
.clickable-card {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.wishlist-container {
position: relative;
z-index: 2;
}
.discount_text {
color: white;
background-color: blueviolet;
font-size: 13px;
font-family: 'Poppins';
/* font-weight: 500; */
padding: 9px 15px;
border-top-left-radius: 10px;
border-bottom-right-radius: 10px;
}
</style>
<section style="background-color: #e6eef7;">
<div class="container">
<div class="row">
<div class="col-md-12" style="padding: 30px 150px;">
<h2 style="font-family: 'Poppins';color: #00006b;font-size: 30px;letter-spacing: 1px;" class="search_result_heading">Search Results:</h2>
</div>
<?php
// Check if results exist
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$wishlist_status = in_array($row['p_id'], $wishlist) ? 0 : 1;
?>
<div class="col-md-12 search_product_card">
<!-- Invisible link for the entire card -->
<a href="single_product.php?id=<?php echo htmlspecialchars($row['p_id']); ?>" class="clickable-card"></a>
<!-- Product image and wishlist button -->
<div class="col-md-3 search_product_image bg-light wishlist-container">
<div class="col-md-12 d-flex" style="align-items: end;justify-content: right;">
<button class="btn border-0" data="<?php echo $wishlist_status; ?>" onclick="
<?php if (!isset($_SESSION['username'])) { ?>
alert('Please log in to add items to your wishlist.');
<?php } else { ?>
wishlist_add(<?php echo $row['p_id']; ?>, this);
<?php } ?>">
<i class="fa-lg fa-heart heart_red <?php echo ($wishlist_status == 0) ? "fa" : "fa-regular"; ?>"></i>
</button>
</div>
<img src="assest/product_image/<?php echo htmlspecialchars($row['product_image']); ?>"
alt="<?php echo htmlspecialchars($row['product_name']); ?>">
</div>
<!-- Product description -->
<div class="col-md-5 search_product_description">
<h6 class="category_name text-start"><?php echo htmlspecialchars($row['category_name']); ?></h6>
<h4><?php echo htmlspecialchars($row['product_name']); ?></h4>
<img src="assest/img/5star.png" width="80px;" class="mb-2">
<p style="text-align: justify;font-size: 14px;color: #565656;"><?php echo htmlspecialchars($row['product_details']); ?></p>
</div>
<!-- Product price and delivery date -->
<div class="col-md-4 search_product_price bg-light" style="padding: 20px 40px;display: flex;justify-content: center;align-items: center;">
<div class="search_product_price_content">
<div class="clickbase_assured_tray d-flex">
<img src="assest/img/Background.png" width="40px;" class="mb-2">
<h3 class="assure" style="font-size: 20px;color: blue;font-family: 'Poppins';font-weight: 600;font-style: italic;margin-top: 5px;">Assured</h3>
</div>
<h5 class="text-secondary text-start">MRP: <span class="mrp"><?php echo $row['MRP']; ?></span></h5>
<div class="price_tray d-flex">
<h3 class="price text-start me-3">₹ <?php echo $row['price']; ?></h3>
<h6 class="discount_text text-start"><?php echo $row['discount']; ?>% Off</h6>
</div>
<p class="delivery_date">Expected delivery date: <?php echo $expected_delivery_date; ?></p>
</div>
</div>
</div>
<?php
}
} else {
echo "<h2>No products found for '$search_term'.</h2>";
}
?>
</div>
</div>
</section>
<?php
include("footer.php");
?>