query("SELECT DISTINCT brand FROM cars ORDER BY brand")->fetchAll(PDO::FETCH_COLUMN); $years = $pdo->query("SELECT DISTINCT year FROM cars ORDER BY year DESC")->fetchAll(PDO::FETCH_COLUMN); } catch (Exception $e) { $brands = []; $years = []; } // Build Query $where = ["status = 'available'"]; $params = []; if (!empty($_GET['brand'])) { $where[] = "brand = ?"; $params[] = $_GET['brand']; } if (!empty($_GET['year'])) { $where[] = "year = ?"; $params[] = $_GET['year']; } if (!empty($_GET['max_price'])) { $where[] = "price <= ?"; $params[] = $_GET['max_price']; } $sql = "SELECT * FROM cars WHERE " . implode(" AND ", $where) . " ORDER BY created_at DESC"; try { $stmt = $pdo->prepare($sql); $stmt->execute($params); $cars = $stmt->fetchAll(); } catch (Exception $e) { $cars = []; } ?>
Browse our premium selection of vehicles.
No cars found matching your criteria.