&$prodList) {
/**
* @var int|false $key Der Array-Index der Produkt-ID in der aktuellen Kategorie-Liste.
*/
$key = array_search($removeId, $prodList);
if ($key !== false) {
// Das Produkt wurde gefunden und wird aus dem Array entfernt.
unset($prodList[$key]);
}
}
// Referenz auf $prodList löschen, um unbeabsichtigte Nebeneffekte zu vermeiden.
unset($prodList);
}
}
?>
Produktvergleich
$productIds) {
// Wenn die Liste der Produkte für diese Kategorie leer ist, überspringen wir sie.
if (empty($productIds)) continue;
// Setze Flag auf true, da mindestens ein zu vergleichendes Produkt existiert.
$hasProducts = true;
/**
* @var string $catName Der Standardname der Kategorie (wird überschrieben, falls in der DB gefunden).
*/
$catName = "Kategorie $categoryId";
/**
* @brief Holt den echten Namen der Kategorie aus der Datenbank.
*/
$stmtCat = $conn->prepare("SELECT name FROM categories WHERE categoryID = ?");
if ($stmtCat) {
$stmtCat->bind_param("i", $categoryId);
$stmtCat->execute();
/** @var mysqli_result $resCat Das Ergebnis der Abfrage des Kategorienamens. */
$resCat = $stmtCat->get_result();
if ($row = $resCat->fetch_assoc()) {
$catName = $row['name'];
}
$stmtCat->close();
}
/**
* @var array $attributes Sammelt alle Attribute (Eigenschaften), die zu dieser Kategorie gehören.
* Format: $attributes[attributeID] = [ 'attributeID' => ..., 'name' => ..., 'unit' => ..., 'dataType' => ... ]
*/
$attributes = [];
/**
* @brief Holt die Kategorie-Attribute mit Namen, Einheit und Datentyp.
*/
$stmtAttr = $conn->prepare("
SELECT a.attributeID, a.name, a.unit, a.dataType
FROM categoryAttributes ca
JOIN attributes a ON ca.attributeID = a.attributeID
WHERE ca.categoryID = ?
ORDER BY a.attributeID
");
if ($stmtAttr) {
$stmtAttr->bind_param("i", $categoryId);
$stmtAttr->execute();
/** @var mysqli_result $resAttr Das Ergebnis der Abfrage der Kategorie-Attribute. */
$resAttr = $stmtAttr->get_result();
while ($row = $resAttr->fetch_assoc()) {
$attributes[$row['attributeID']] = $row;
}
$stmtAttr->close();
}
/**
* @var array $products Sammelt die Grunddaten der zugehörigen Produkte (Model, Bild, Beschreibung).
* Format: $products[productID] = [ ... Produktdaten ... ]
*/
$products = [];
/**
* @var string $idList Kommaseparierte Liste der zu vergleichenden Produkt-IDs, escapet als Integers für den IN-Query.
*/
$idList = implode(',', array_map('intval', $productIds));
/**
* @brief Holt die Produktinformationen für die IN-Klausel Liste.
*/
$stmtProd = $conn->query("SELECT productID, model, imagePath, description FROM products WHERE productID IN ($idList)");
if ($stmtProd) {
while ($row = $stmtProd->fetch_assoc()) {
$products[$row['productID']] = $row;
}
}
/**
* @var array $productAttrVals Sammelt die spezifischen Attribut-Werte je Produkt.
* Format: $productAttrVals[productID][attributeID] = [ ... Attributwerte ... ]
*/
$productAttrVals = [];
/**
* @brief Holt die Werte (String, Number, Bool) der Attribute für die ausgewählten Produkte.
*/
$stmtProdAttr = $conn->query("SELECT productID, attributeID, valueString, valueNumber, valueBool FROM productAttributes WHERE productID IN ($idList)");
if ($stmtProdAttr) {
while ($row = $stmtProdAttr->fetch_assoc()) {
$productAttrVals[$row['productID']][$row['attributeID']] = $row;
}
$stmtProdAttr->close();
}
?>
= htmlspecialchars($catName) ?>
| Eigenschaft |
|
| Beschreibung |
= htmlspecialchars($products[$pId]['description']) ?>
|
$attr): ?>
| = htmlspecialchars($attr['name'] ?? '') ?> |
|
Du hast noch keine Produkte zum Vergleich hinzugefügt. Gehe auf eine Produktseite, um Produkte hinzuzufügen.
";
}
?>