Refactor productpage to use LEFT JOINs for category and attribute tables, add error handling for missing products, and improve output formatting for product attributes
This commit is contained in:
parent
5caae9501f
commit
4575b92e68
@ -98,10 +98,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_review']) && i
|
|||||||
p.categoryID
|
p.categoryID
|
||||||
FROM products p
|
FROM products p
|
||||||
|
|
||||||
INNER JOIN categoryAttributes ca
|
LEFT JOIN categoryAttributes ca
|
||||||
ON p.categoryID = ca.categoryID
|
ON p.categoryID = ca.categoryID
|
||||||
|
|
||||||
INNER JOIN attributes a
|
LEFT JOIN attributes a
|
||||||
ON ca.attributeID = a.attributeID
|
ON ca.attributeID = a.attributeID
|
||||||
|
|
||||||
LEFT JOIN productAttributes pa
|
LEFT JOIN productAttributes pa
|
||||||
@ -119,6 +119,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_review']) && i
|
|||||||
|
|
||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
$product = $result->fetch_assoc();
|
$product = $result->fetch_assoc();
|
||||||
|
if (!$product) {
|
||||||
|
die("Produkt nicht gefunden.");
|
||||||
|
}
|
||||||
$categoryId = $product['categoryID'];
|
$categoryId = $product['categoryID'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -357,7 +360,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
<div class="product-specs">
|
<div class="product-specs">
|
||||||
<div class="product-desc">
|
<div class="product-desc">
|
||||||
<?= htmlspecialchars($product['description']) ?>
|
<?= htmlspecialchars($product['description'] ?? '') ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@ -366,10 +369,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
* @details Iteriert durch die vorab geladenen Attribute und formatiert die Ausgabe
|
* @details Iteriert durch die vorab geladenen Attribute und formatiert die Ausgabe
|
||||||
* entsprechend den Datentypen (String, Number, Boolean).
|
* entsprechend den Datentypen (String, Number, Boolean).
|
||||||
*/
|
*/
|
||||||
|
if (!empty($product['name'])) {
|
||||||
|
echo "<p><strong>{$product['name']}:</strong> ";
|
||||||
|
if (!empty($product['valueString'])) echo htmlspecialchars($product['valueString']);
|
||||||
|
if (!empty($product['valueNumber'])) echo htmlspecialchars($product['valueNumber'] . " " . $product['unit']);
|
||||||
|
if (!is_null($product['valueBool'])) echo $product['valueBool'] ? "Ja" : "Nein";
|
||||||
|
echo "</p>";
|
||||||
|
}
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
if (empty($row['name'])) continue;
|
||||||
echo "<p><strong>{$row['name']}:</strong> ";
|
echo "<p><strong>{$row['name']}:</strong> ";
|
||||||
if (!empty($row['valueString'])) echo $row['valueString'];
|
if (!empty($row['valueString'])) echo htmlspecialchars($row['valueString']);
|
||||||
if (!empty($row['valueNumber'])) echo $row['valueNumber'] . " " . $row['unit'];
|
if (!empty($row['valueNumber'])) echo htmlspecialchars($row['valueNumber'] . " " . $row['unit']);
|
||||||
if (!is_null($row['valueBool'])) echo $row['valueBool'] ? "Ja" : "Nein";
|
if (!is_null($row['valueBool'])) echo $row['valueBool'] ? "Ja" : "Nein";
|
||||||
echo "</p>";
|
echo "</p>";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user