feat: add search functionality with results display and remove autocomplete script
This commit is contained in:
parent
a250189b08
commit
c1cb39e083
@ -11,6 +11,64 @@ error_reporting(E_ALL);
|
|||||||
$conn = db_connect();
|
$conn = db_connect();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// ─────────────────────────────────────────────
|
||||||
|
// Reine PHP-Suche (GET ?search=...)
|
||||||
|
// Wenn ein Suchbegriff vorhanden ist, zeigen wir nur Suchergebnisse
|
||||||
|
// (statt der Kategorie-Sektionen).
|
||||||
|
// ─────────────────────────────────────────────
|
||||||
|
$searchTerm = isset($_GET['search']) ? trim((string)$_GET['search']) : '';
|
||||||
|
if ($searchTerm !== '' && mb_strlen($searchTerm, 'UTF-8') >= 2) {
|
||||||
|
$like = addcslashes($searchTerm, "%_\\");
|
||||||
|
$like = '%' . $like . '%';
|
||||||
|
|
||||||
|
$stmtSearch = $conn->prepare("
|
||||||
|
SELECT productID, model, description, imagePath
|
||||||
|
FROM products
|
||||||
|
WHERE model LIKE ? OR description LIKE ?
|
||||||
|
ORDER BY model ASC
|
||||||
|
LIMIT 60
|
||||||
|
");
|
||||||
|
|
||||||
|
if ($stmtSearch) {
|
||||||
|
$stmtSearch->bind_param('ss', $like, $like);
|
||||||
|
$stmtSearch->execute();
|
||||||
|
$resultSearch = $stmtSearch->get_result();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<section class="product-section">
|
||||||
|
<h2>Suchergebnisse für „<?= htmlspecialchars($searchTerm) ?>“</h2>
|
||||||
|
|
||||||
|
<?php if ($resultSearch->num_rows <= 0): ?>
|
||||||
|
<p style="color: var(--text-secondary); margin-top: 8px;">Keine Produkte gefunden.</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="product-grid" style="margin-top: 14px;">
|
||||||
|
<?php while ($product = $resultSearch->fetch_assoc()): ?>
|
||||||
|
<?php $productId = (int)$product['productID']; ?>
|
||||||
|
<a class="product-card" href="productpage.php?id=<?= $productId ?>">
|
||||||
|
<img
|
||||||
|
src="<?= !empty($product['imagePath']) ? htmlspecialchars($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>
|
||||||
|
</a>
|
||||||
|
<?php endwhile; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$stmtSearch->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wichtig: In Suchmodus KEINE Kategorien rendern.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$activeCategory = isset($_GET['category']) ? $_GET['category'] : 'all';
|
$activeCategory = isset($_GET['category']) ? $_GET['category'] : 'all';
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -162,6 +162,3 @@
|
|||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Produktsuche (Autocomplete Dropdown) -->
|
|
||||||
<script src="assets/js/search-autocomplete.js" defer></script>
|
|
||||||
|
|
||||||
|
|||||||
@ -239,7 +239,7 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
$stmt = mysqli_prepare($conn,
|
$stmt = mysqli_prepare($conn,
|
||||||
"SELECT price, shippingCost, inStock, shops.name, offers.offerURL, shops.logoPath, shops.shippingTime
|
"SELECT price, shippingCost, inStock, shops.name, offers.productURL, shops.logoPath, shops.shippingTime
|
||||||
FROM offers
|
FROM offers
|
||||||
INNER JOIN shops ON
|
INNER JOIN shops ON
|
||||||
offers.shopID = shops.shopID WHERE offers.productID = ? ORDER BY offers.price ASC");
|
offers.shopID = shops.shopID WHERE offers.productID = ? ORDER BY offers.price ASC");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user