34968-vm/search.php
Flatlogic Bot ec17506c33 V9
2025-10-15 02:41:21 +00:00

49 lines
1.8 KiB
PHP

<?php
require_once 'header.php';
require_once 'db/config.php';
$query = $_GET['query'] ?? '';
$db = db();
if ($query) {
$stmt = $db->prepare(
'SELECT r.*, COALESCE(AVG(ra.rating), 0) as rating, COUNT(ra.id) as rating_count '
. 'FROM restaurants r LEFT JOIN ratings ra ON r.id = ra.restaurant_id '
. 'WHERE r.name LIKE ? OR r.cuisine LIKE ? GROUP BY r.id'
);
$stmt->execute(['%' . $query . '%', '%' . $query . '%']);
$restaurants = $stmt->fetchAll();
} else {
$restaurants = [];
}
?>
<main class="container">
<h1 class="page-title">Search Results for "<?php echo htmlspecialchars($query); ?>"</h1>
<div class="restaurant-list">
<?php if (empty($restaurants)): ?>
<p>No restaurants found.</p>
<?php else: ?>
<?php foreach ($restaurants as $restaurant): ?>
<div class="restaurant-card">
<a href="menu.php?restaurant_id=<?php echo $restaurant['id']; ?>">
<img src="<?php echo htmlspecialchars($restaurant['image_url']); ?>" alt="<?php echo htmlspecialchars($restaurant['name']); ?>">
<div class="restaurant-info">
<h3><?php echo htmlspecialchars($restaurant['name']); ?></h3>
<p><?php echo htmlspecialchars($restaurant['cuisine']); ?></p>
<div class="rating">
<span>★ <?php echo number_format($restaurant['rating'], 1); ?></span>
<span>(<?php echo $restaurant['rating_count']; ?>)</span>
</div>
</div>
</a>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</main>
<?php require_once 'footer.php'; ?>