update
This commit is contained in:
parent
96415532d2
commit
61fb2ee229
2
header.php
Normal file
2
header.php
Normal file
@ -0,0 +1,2 @@
|
||||
<header>
|
||||
|
||||
169
index.php
Executable file → Normal file
169
index.php
Executable file → Normal file
@ -1,169 +1,2 @@
|
||||
<?php
|
||||
// ====================================== 123 123123
|
||||
// Fehleranzeige (DEV)
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// ======================================
|
||||
// DB-Verbindung
|
||||
$con = mysqli_connect("localhost", "FSST", "L9wUNZZ9Qkbt", "FSST");
|
||||
mysqli_set_charset($con, "utf8");
|
||||
|
||||
if (!$con) {
|
||||
die("DB Fehler: " . mysqli_connect_error());
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// GET-Parameter
|
||||
$categoryID = isset($_GET['category']) ? (int)$_GET['category'] : 0;
|
||||
$maxPrice = isset($_GET['maxPrice']) ? (float)$_GET['maxPrice'] : 0;
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Preisvergleich – Demo</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link rel="stylesheet" href="style.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<?php include 'navbar.php'; ?>
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>💻 Preisvergleich – Beispielanwendung</h1>
|
||||
|
||||
<?php
|
||||
// ======================================
|
||||
// Kategorien laden
|
||||
$categories = mysqli_query($con, "
|
||||
SELECT categoryID, name
|
||||
FROM categories
|
||||
WHERE parentCategoryID IS NOT NULL
|
||||
ORDER BY name
|
||||
");
|
||||
?>
|
||||
|
||||
<form method="get">
|
||||
Kategorie:
|
||||
<select name="category">
|
||||
<option value="0">Alle</option>
|
||||
<?php while ($c = mysqli_fetch_assoc($categories)): ?>
|
||||
<option value="<?= $c['categoryID'] ?>"
|
||||
<?= $categoryID === (int)$c['categoryID'] ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($c['name']) ?>
|
||||
</option>
|
||||
<?php endwhile; ?>
|
||||
</select>
|
||||
|
||||
Max Preis (€):
|
||||
<input type="number" step="1" name="maxPrice" value="<?= htmlspecialchars($maxPrice) ?>">
|
||||
|
||||
<button type="submit">Anzeigen</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
// ======================================
|
||||
// Produkte + günstigster Preis
|
||||
$sql = "
|
||||
SELECT
|
||||
p.productID,
|
||||
p.model,
|
||||
b.name AS brand,
|
||||
c.name AS category,
|
||||
MIN(o.price + o.shippingCost) AS bestPrice
|
||||
FROM products p
|
||||
JOIN brands b ON p.brandID = b.brandID
|
||||
JOIN categories c ON p.categoryID = c.categoryID
|
||||
JOIN offers o ON o.productID = p.productID
|
||||
WHERE 1
|
||||
";
|
||||
|
||||
$params = [];
|
||||
$types = "";
|
||||
|
||||
if ($categoryID > 0) {
|
||||
$sql .= " AND p.categoryID = ?";
|
||||
$params[] = $categoryID;
|
||||
$types .= "i";
|
||||
}
|
||||
|
||||
if ($maxPrice > 0) {
|
||||
$sql .= " AND (o.price + o.shippingCost) <= ?";
|
||||
$params[] = $maxPrice;
|
||||
$types .= "d";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY p.productID ORDER BY bestPrice ASC";
|
||||
|
||||
$stmt = mysqli_prepare($con, $sql);
|
||||
if ($params) {
|
||||
mysqli_stmt_bind_param($stmt, $types, ...$params);
|
||||
}
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
|
||||
// ======================================
|
||||
// Ausgabe
|
||||
while ($p = mysqli_fetch_assoc($result)):
|
||||
?>
|
||||
<div class="product">
|
||||
<strong><?= htmlspecialchars($p['brand']) ?> <?= htmlspecialchars($p['model']) ?></strong><br>
|
||||
Kategorie: <?= htmlspecialchars($p['category']) ?><br>
|
||||
💰 Ab <?= number_format($p['bestPrice'], 2, ',', '.') ?> €
|
||||
|
||||
<div class="spec">
|
||||
<strong>Specs:</strong><br>
|
||||
<?php
|
||||
$specs = mysqli_query($con, "
|
||||
SELECT a.name, a.unit,
|
||||
pa.valueString, pa.valueNumber, pa.valueBool
|
||||
FROM productAttributes pa
|
||||
JOIN attributes a ON pa.attributeID = a.attributeID
|
||||
WHERE pa.productID = {$p['productID']}
|
||||
");
|
||||
|
||||
while ($s = mysqli_fetch_assoc($specs)) {
|
||||
echo htmlspecialchars($s['name']) . ": ";
|
||||
|
||||
if ($s['valueString'] !== null) echo htmlspecialchars($s['valueString']);
|
||||
elseif ($s['valueNumber'] !== null) echo htmlspecialchars($s['valueNumber']) . " " . $s['unit'];
|
||||
elseif ($s['valueBool'] !== null) echo $s['valueBool'] ? "Ja" : "Nein";
|
||||
|
||||
echo "<br>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="offer">
|
||||
<strong>Angebote:</strong><br>
|
||||
<?php
|
||||
$offers = mysqli_query($con, "
|
||||
SELECT s.name, o.price, o.shippingCost
|
||||
FROM offers o
|
||||
JOIN shops s ON o.shopID = s.shopID
|
||||
WHERE o.productID = {$p['productID']}
|
||||
ORDER BY o.price ASC
|
||||
");
|
||||
|
||||
while ($o = mysqli_fetch_assoc($offers)) {
|
||||
$total = $o['price'] + $o['shippingCost'];
|
||||
echo htmlspecialchars($o['name']) . ": "
|
||||
. number_format($total, 2, ',', '.') . " €<br>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php mysqli_close($con); ?>
|
||||
echo "Test123";
|
||||
@ -10,7 +10,7 @@ $currentPage = basename($_SERVER['PHP_SELF']);
|
||||
<a href="index.php">Wunschliste</a>
|
||||
</li>
|
||||
<li class="<?= $currentPage === 'produkte.php' ? 'active' : '' ?>">
|
||||
<a href="produkte.php">Wahrenkorb</a>
|
||||
<a href="produkte.php">Warenkorb</a>
|
||||
</li>
|
||||
<li class="<?= $currentPage === 'kontakt.php' ? 'active' : '' ?>">
|
||||
<a href="kontakt.php">Account</a>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user