20, 'ipad' => 21, 'macbook' => 22, 'airpods' => 23, 'accessories' => 24, ]; if (isset($categoriesConfig[$currentCategory])) { $catId = $categoriesConfig[$currentCategory]; } // Fetch available attributes for the category if selected $attributes = []; if ($catId) { // Only show attributes related to the products in the active category $stmtAttr = $conn->prepare(" SELECT DISTINCT a.attributeID, a.name, a.unit FROM attributes a JOIN productAttributes pa ON a.attributeID = pa.attributeID JOIN products p ON pa.productID = p.productID WHERE p.categoryID = ? ORDER BY a.name "); $stmtAttr->bind_param("i", $catId); $stmtAttr->execute(); $resAttr = $stmtAttr->get_result(); while ($row = $resAttr->fetch_assoc()) { $attributes[] = $row; } $stmtAttr->close(); } else { // Or all active across any product? // User typically filters by category first. But if 'all', maybe just get top attributes. $resAttr = $conn->query(" SELECT DISTINCT a.attributeID, a.name, a.unit FROM attributes a JOIN productAttributes pa ON a.attributeID = pa.attributeID ORDER BY a.name LIMIT 5 "); if ($resAttr) { while ($row = $resAttr->fetch_assoc()) { $attributes[] = $row; } } } ?>
prepare(" SELECT DISTINCT pa.valueString, pa.valueNumber, pa.valueBool FROM productAttributes pa JOIN products p ON pa.productID = p.productID WHERE p.categoryID = ? AND pa.attributeID = ? ORDER BY pa.valueString, pa.valueNumber "); $vStmt->bind_param("ii", $catId, $attrId); } else { $vStmt = $conn->prepare(" SELECT DISTINCT valueString, valueNumber, valueBool FROM productAttributes WHERE attributeID = ? ORDER BY valueString, valueNumber "); $vStmt->bind_param("i", $attrId); } $vStmt->execute(); $vRes = $vStmt->get_result(); $values = []; while ($vRow = $vRes->fetch_assoc()) { if ($vRow['valueString'] !== null) $values[] = $vRow['valueString']; elseif ($vRow['valueNumber'] !== null) $values[] = $vRow['valueNumber']; elseif ($vRow['valueBool'] !== null) $values[] = $vRow['valueBool'] ? 'Ja' : 'Nein'; } $vStmt->close(); if (empty($values)) continue; $paramName = "attr_" . $attrId; $selectedValue = isset($_GET[$paramName]) ? $_GET[$paramName] : ''; ?>
$v) { if (strpos($k, 'attr_') === 0 && $v !== '') { $hasActiveFilter = true; break; } } if ($hasActiveFilter): ?> Filter zurücksetzen