-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_items.php
32 lines (27 loc) · 1.07 KB
/
filter_items.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
<?php
include './Includes/connection.php';
// Create a new instance of the connection class
$db = new connection();
$conn = $db->getConnection();
// ...
// Get the selected category or sub-category from the post data
$selectedCategory = isset($_POST['category']) ? $_POST['category'] : null;
$selectedSubCategory = isset($_POST['sub_category']) ? $_POST['sub_category'] : null;
// Modify the SQL query based on the selected category or sub-category
$sql = "SELECT productName, price, images FROM clothing_items WHERE ";
if ($selectedSubCategory) {
$sql .= "sub_category = :sub_category";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':sub_category', $selectedSubCategory);
} elseif ($selectedCategory) {
$sql .= "category = :category";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':category', $selectedCategory);
} else {
// Default query without any filters
$stmt = $conn->query("SELECT productName, price, images FROM clothing_items");
}
// Execute the query and fetch results
$stmt->execute();
$clothingItems = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>