dynamic product cards
This commit is contained in:
parent
7a7fff3a02
commit
ff58525672
12
catbar.php
12
catbar.php
@ -12,27 +12,27 @@
|
|||||||
<ul class="home-nav__list">
|
<ul class="home-nav__list">
|
||||||
|
|
||||||
<li class="home-nav__item">
|
<li class="home-nav__item">
|
||||||
<a href="?category=iphone" class="cat-btn">iPhone</a>
|
<button onclick="location.href='index.php?category=iphone'">iPhone</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="home-nav__item">
|
<li class="home-nav__item">
|
||||||
<a href="?category=ipad" class="cat-btn">iPad</a>
|
<button onclick="location.href='index.php?category=ipad'">iPad</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="home-nav__item">
|
<li class="home-nav__item">
|
||||||
<a href="?category=macbook" class="cat-btn">MacBook</a>
|
<button onclick="location.href='index.php?category=macbook'">MacBook</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="home-nav__item">
|
<li class="home-nav__item">
|
||||||
<a href="?category=airpods" class="cat-btn">AirPods</a>
|
<button onclick="location.href='index.php?category=airpods'">AirPods</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="home-nav__item">
|
<li class="home-nav__item">
|
||||||
<a href="?category=watch" class="cat-btn">Watch</a>
|
<button onclick="location.href='index.php?category=watch'">Watch</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="home-nav__item">
|
<li class="home-nav__item">
|
||||||
<a href="?category=others" class="cat-btn">Others</a>
|
<button onclick="location.href='index.php?category=accessories'">Accessories</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
124
compcards.php
124
compcards.php
@ -1,44 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
// login.php
|
||||||
|
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// 1) DB-Verbindung (einmal)
|
||||||
|
$servername = "localhost";
|
||||||
|
$port = 3306;
|
||||||
|
$username = "FSST";
|
||||||
|
$password = "L9wUNZZ9Qkbt";
|
||||||
|
$db = "FSST";
|
||||||
|
|
||||||
|
$conn = mysqli_connect($servername, $username, $password, $db, $port);
|
||||||
|
if (!$conn)
|
||||||
|
{
|
||||||
|
http_response_code(500);
|
||||||
|
die("Datenbankfehler");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$activeCategory = isset($_GET['category']) ? $_GET['category'] : 'all';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$categories = [
|
||||||
|
'iphone' => ['id' => 20, 'label' => 'iPhone'],
|
||||||
|
'ipad' => ['id' => 21, 'label' => 'iPad'],
|
||||||
|
'macbook' => ['id' => 22, 'label' => 'MacBook'],
|
||||||
|
'airpods' => ['id' => 23, 'label' => 'AirPods'],
|
||||||
|
'accessories' => ['id' => 24, 'label' => 'Accessories'],
|
||||||
|
];
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<?php foreach ($categories as $key => $cat): ?>
|
||||||
|
|
||||||
|
<?php if ($activeCategory === 'all' || $activeCategory === $key): ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$stmt = $conn->prepare("
|
||||||
|
SELECT productID, model, description, imagePath
|
||||||
|
FROM products
|
||||||
|
WHERE categoryID = ?
|
||||||
|
");
|
||||||
|
|
||||||
|
$stmt->bind_param("i", $cat['id']); // i = integer
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php if ($result->num_rows > 0): ?>
|
||||||
|
<section class="product-section">
|
||||||
|
<h2><?= htmlspecialchars($cat['label']) ?></h2>
|
||||||
|
|
||||||
|
<div class="product-scroll">
|
||||||
|
<?php while ($product = $result->fetch_assoc()): ?>
|
||||||
|
<div class="product-card">
|
||||||
|
<img
|
||||||
|
src="<?= isset($product['imagePath']) ? $product['imagePath'] : 'assets/images/placeholder.png' ?>"
|
||||||
|
alt="<?= htmlspecialchars($product['model']) ?>">
|
||||||
|
|
||||||
|
<div class="product-card__content">
|
||||||
|
<h3><?= htmlspecialchars($product['model']) ?></h3>
|
||||||
|
<p><?= htmlspecialchars($product['description']) ?></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endwhile; ?>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php $stmt->close(); ?>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
<link rel="stylesheet" href="assets/css/compcard.css">
|
<link rel="stylesheet" href="assets/css/compcard.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<?php
|
|
||||||
$activeCategory = $_GET['category'] ?? 'all';
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
<?php if ($activeCategory === 'iphone' || $activeCategory === 'all'): ?>
|
|
||||||
<section class="product-section">
|
|
||||||
<h2>iPhone</h2>
|
|
||||||
<div class="product-scroll">
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($activeCategory === 'ipad' || $activeCategory === 'all'): ?>
|
|
||||||
<section class="product-section">
|
|
||||||
<h2>iPad</h2>
|
|
||||||
<div class="product-scroll">
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($activeCategory === 'macbook' || $activeCategory === 'all'): ?>
|
|
||||||
<section class="product-section">
|
|
||||||
<h2>MacBook</h2>
|
|
||||||
<div class="product-scroll">
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
<div class="product-card">...</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<?php endif; ?>
|
|
||||||
Loading…
Reference in New Issue
Block a user