prepare("SELECT value FROM settings WHERE name = ?"); $stmt_shutdown->execute(['emergency_shutdown']); $shutdown_active = ($stmt_shutdown->fetchColumn() === 'true'); // Fetch all cuisines for the filter dropdown $cuisines_stmt = db()->query("SELECT * FROM cuisines ORDER BY name"); $cuisines = $cuisines_stmt->fetchAll(PDO::FETCH_ASSOC); // Base query // Corrected GROUP_CONCAT for PostgreSQL $sql = "SELECT r.id, r.name, r.image_url, STRING_AGG(c.name, ', ') as cuisines, AVG(ra.rating) as average_rating FROM restaurants r LEFT JOIN restaurant_cuisines rc ON r.id = rc.restaurant_id LEFT JOIN cuisines c ON rc.cuisine_id = c.id LEFT JOIN ratings ra ON r.id = ra.restaurant_id"; $where_clauses = []; $params = []; // Search functionality if (!empty($_GET['search'])) { $where_clauses[] = "r.name ILIKE :search"; // ILIKE for case-insensitive search in PostgreSQL $params[':search'] = '%' . $_GET['search'] . '%'; } // Cuisine filter if (!empty($_GET['cuisine'])) { $where_clauses[] = "r.id IN (SELECT restaurant_id FROM restaurant_cuisines WHERE cuisine_id = :cuisine_id)"; $params[':cuisine_id'] = $_GET['cuisine']; } if (!empty($where_clauses)) { $sql .= " WHERE " . implode(' AND ', $where_clauses); } $sql .= " GROUP BY r.id"; // Sorting functionality $sort_order = $_GET['sort'] ?? 'name_asc'; switch ($sort_order) { case 'rating_desc': $sql .= " ORDER BY average_rating DESC NULLS LAST"; break; case 'name_desc': $sql .= " ORDER BY r.name DESC"; break; default: $sql .= " ORDER BY r.name ASC"; break; } $stmt = db()->prepare($sql); $stmt->execute($params); $restaurants = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>

Our Restaurants

Explore a variety of cuisines from the best local restaurants.

No Restaurants Found

Try adjusting your search or filters to find what you're looking for.