90 lines
4.2 KiB
PHP
90 lines
4.2 KiB
PHP
<?php include 'header.php'; ?>
|
|
|
|
<main>
|
|
<section class="hero">
|
|
<div class="hero-content">
|
|
<h1>Order from Majuro's best</h1>
|
|
<form action="index.php" method="get" class="search-form">
|
|
<input type="text" name="search" class="search-bar" placeholder="Search restaurants..." value="<?= isset($_GET['search']) ? htmlspecialchars($_GET['search']) : '' ?>">
|
|
|
|
<?php
|
|
require_once 'db/config.php';
|
|
$pdo = db();
|
|
$cuisine_stmt = $pdo->query("SELECT DISTINCT cuisine FROM restaurants ORDER BY cuisine");
|
|
$cuisines = $cuisine_stmt->fetchAll(PDO::FETCH_COLUMN);
|
|
?>
|
|
<select name="cuisine" class="cuisine-filter">
|
|
<option value="">All Cuisines</option>
|
|
<?php foreach ($cuisines as $cuisine): ?>
|
|
<option value="<?= htmlspecialchars($cuisine) ?>" <?= (isset($_GET['cuisine']) && $_GET['cuisine'] == $cuisine) ? 'selected' : '' ?>><?= htmlspecialchars($cuisine) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
|
|
<button type="submit" class="search-button">Filter</button>
|
|
</form>
|
|
</div>
|
|
</section>
|
|
|
|
<div class="container">
|
|
<h2 class="page-title">All Restaurants</h2>
|
|
|
|
<section class="restaurant-list">
|
|
<div class="restaurant-grid" id="restaurant-grid">
|
|
<?php
|
|
// Base query
|
|
$sql = "SELECT id, name, cuisine, image_url, rating, rating_count FROM restaurants";
|
|
$params = [];
|
|
$where_clauses = [];
|
|
|
|
// Append search condition
|
|
if (!empty($_GET['search'])) {
|
|
$where_clauses[] = "name LIKE ?";
|
|
$params[] = '%' . $_GET['search'] . '%';
|
|
}
|
|
|
|
// Append cuisine filter
|
|
if (!empty($_GET['cuisine'])) {
|
|
$where_clauses[] = "cuisine = ?";
|
|
$params[] = $_GET['cuisine'];
|
|
}
|
|
|
|
if (!empty($where_clauses)) {
|
|
$sql .= " WHERE " . implode(' AND ', $where_clauses);
|
|
}
|
|
|
|
$sql .= " ORDER BY name";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
$restaurants = $stmt->fetchAll();
|
|
|
|
if (empty($restaurants)) {
|
|
echo '<p>No restaurants found matching your criteria.</p>';
|
|
} else {
|
|
foreach ($restaurants as $restaurant) {
|
|
echo '<a href="menu.php?id=' . htmlspecialchars($restaurant['id']) . '" class="restaurant-card">';
|
|
echo '<img src="' . htmlspecialchars($restaurant['image_url']) . '" alt="' . htmlspecialchars($restaurant['name']) . '">';
|
|
echo '<div class="restaurant-card-content">';
|
|
echo '<h3>' . htmlspecialchars($restaurant['name']) . '</h3>';
|
|
echo '<p>' . htmlspecialchars($restaurant['cuisine']) . '</p>';
|
|
if (isset($restaurant['rating']) && $restaurant['rating'] > 0) {
|
|
echo '<div class="rating-display">';
|
|
echo '<span class="star">★</span>';
|
|
echo '<span>' . htmlspecialchars(number_format($restaurant['rating'], 1)) . '</span>';
|
|
echo '<span class="rating-count">(' . htmlspecialchars($restaurant['rating_count']) . ' ratings)</span>';
|
|
echo '</div>';
|
|
} else {
|
|
echo '<div class="rating-display"><span class="rating-count">No ratings yet</span></div>';
|
|
}
|
|
echo '</div>';
|
|
echo '</a>';
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</main>
|
|
|
|
<?php include 'footer.php'; ?>
|