Repository navigation
Expand file tree
/
Copy pathcategory.php
More file actions
56 lines (50 loc) · 2.36 KB
/
Copy pathcategory.php
File metadata and controls
56 lines (50 loc) · 2.36 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
<?php
require_once 'classes/Product.php';
session_start();
if (!isset($_GET['sub_category']) || empty($_GET['sub_category'])) {
die('Sub-category not specified.');
}
$subCategory = urldecode($_GET['sub_category']);
$product = new Product();
$products = $product->getProductsBySubCategory($subCategory);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($subCategory); ?> Products</title>
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
</head>
<body>
<?php include 'includes/header.php'; ?>
<div class="container mt-5">
<h2 class="text-center mb-4">Products in "<?php echo htmlspecialchars($subCategory); ?>"</h2>
<?php if (empty($products)) : ?>
<div class="alert alert-warning text-center">No products found in this sub-category.</div>
<?php else : ?>
<div class="row">
<?php foreach ($products as $product) : ?>
<div class="col-md-4 mb-4">
<div class="card">
<?php
$images = json_decode($product['images'], true);
$firstImage = $images[0] ?? 'default.jpg';
?>
<img src="uploads/<?php echo htmlspecialchars($firstImage); ?>" class="card-img-top" alt="Product Image">
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($product['name']); ?></h5>
<p class="card-text">$<?php echo htmlspecialchars($product['price']); ?></p>
<a href="product.php?id=<?php echo htmlspecialchars($product['id']); ?>" class="btn btn-primary">View Details</a>
<a href="cart.php?action=add&id=<?php echo htmlspecialchars($product['id']); ?>" class="btn btn-success">Add to Cart</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php include 'includes/footer.php'; ?>
</body>
</html>