-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectronics.php
More file actions
147 lines (129 loc) · 5.99 KB
/
Copy pathelectronics.php
File metadata and controls
147 lines (129 loc) · 5.99 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
<?php require_once "conn.php";
require_once "nav.php";
$fileName = __FILE__;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="displayproduct.css">
</head>
<body>
<div class="container-fluid">
<div class="row mainrow">
<div class="col-sm-2 fixed-top">
<?php require_once "ProductSorting.php"; ?>
</div>
<div class="col-sm-10">
<?php
// $category = "Sma";
$sort_by = 'PID ASC';
if (isset($_GET['sort_by'])) {
$sort_by = $_GET['sort_by'];
}
$sql = "SELECT * FROM product WHERE category='electronics' ORDER BY ";
switch ($sort_by) {
case 'price_asc':
$sql .= "MRP ASC";
break;
case 'price_desc':
$sql .= "MRP DESC";
break;
case 'discount_asc':
$sql .= "discount ASC";
break;
case 'discount_desc':
$sql .= "discount DESC";
break;
default:
$sql .= "PID ASC";
}
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
echo '<br><div class="container">';
echo '<div class="row product">';
$count = 0;
while ($row = $result->fetch_assoc()) {
if ($count % 3 == 0 && $count != 0) {
echo '</div><div class="row product">';
}
$pid = $row['PID'];
$stmt1 = $conn->prepare("SELECT img_address FROM images WHERE PID =$pid");
$stmt1->execute();
$imgres = $stmt1->get_result();
$banner_carousel = 0;
$message = '';
$selling_price = (int) $row['MRP'] - $row['MRP'] / 100 * $row['discount'];
echo '<div class="col-md-4">';
echo '<a href="product_detail.php?pid=' . $pid . '" style="text-decoration: none; color: inherit;">';
echo '<div class="card" style="border-radius: 15px;">';
echo '<div class="card-body card_body_img">';
echo '<div class="row">';
echo '<div class="col-sm-12">';
echo '<div class="carousel slide" data-interval="5000" data-ride="carousel">';
echo '<div class="carousel-inner">';
// Display the images
if ($imgres->num_rows > 0) {
while ($_row = $imgres->fetch_assoc()) {
$imagePath = $_row['img_address'];
if (file_exists($imagePath)) {
if ($banner_carousel === 0) {
echo "<div class='carousel-item active'>";
echo '<img src="' . $imagePath . '" class=img-fluid alt="Product Image">';
echo "</div>";
$banner_carousel++;
} else {
echo "<div class='carousel-item'>";
echo '<img src="' . $imagePath . '" class=img-fluid alt="Product Image">';
echo "</div>";
}
} else {
$message++;
}
}
}
if (!$message == 0) {
echo "<p class='text-center text-danger'>Error occured while loading images!</p>";
}
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="card-footer">';
echo '<h5 class="card-title"></h5>';
echo '<p class="card-text"><strong>', $row["product_name"], '</strong></p>';
echo '<p class="card-text"><strong>MRP:</strong><strike>', '₹', $row["MRP"], '</strike></p>';
echo '<p class="card-text"><strong>Discount:</strong><span class="text-success">', $row["discount"], '% off</span></p>';
echo '<p class="card-text"><strong>Selling Price: </strong>', $selling_price, '</p>';
echo '</div>';
echo '</div></a>';
echo '</div>';
$count++;
}
echo '</div>'; // Close the last row
echo '</div><br><br><br>'; // Close the container
} else {
echo "<p><center>No products found.</center></p>";
}
mysqli_close($conn);
?>
</div>
</div>
</div>
</body>
</html>
<script>
function submitForm(event) {
const form = event.target.form;
form.submit();
}
var sort_by_value = '<?php echo $sort_by; ?>';
const sort_by = document.querySelectorAll('.sort_by');
sort_by.forEach(r => {
if (r.value == sort_by_value) {
r.checked = true;
}
});
</script>