38468-vm/cars.php
Flatlogic Bot 0c0cc2ad68 sadiq
2026-02-16 04:29:28 +00:00

61 lines
2.6 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
// Fetch all cars
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM cars ORDER BY created_at DESC");
$stmt->execute();
$cars = $stmt->fetchAll();
} catch (PDOException $e) {
$cars = [];
}
include __DIR__ . '/includes/header.php';
?>
<main>
<section class="hero" style="min-height: 30vh; padding: 60px 0;">
<div class="container">
<h1>Browse <span class="text-gold">Our Collection</span></h1>
<p>Explore our wide range of premium vehicles across Afghanistan.</p>
</div>
</section>
<section class="container mt-4">
<div class="row">
<?php if (empty($cars)): ?>
<div class="col-12 text-center">
<p class="text-muted">No cars available at the moment.</p>
</div>
<?php else: ?>
<?php foreach ($cars as $car): ?>
<div class="col-4">
<div class="glass-card car-card mb-4">
<?php if ($car['is_hot_deal']): ?>
<span class="badge-hot">Hot Deal</span>
<?php endif; ?>
<div class="car-img-container">
<img src="<?php echo htmlspecialchars($car['main_image']); ?>" alt="<?php echo htmlspecialchars($car['brand'] . ' ' . $car['model']); ?>" class="car-img" onerror="this.src='https://images.pexels.com/photos/170811/pexels-photo-170811.jpeg?auto=compress&cs=tinysrgb&w=600'">
</div>
<div class="car-info">
<h3><?php echo htmlspecialchars($car['brand'] . ' ' . $car['model']); ?></h3>
<div class="car-details">
<span>Year: <?php echo $car['year']; ?></span>
<span>City: <?php echo htmlspecialchars($car['city']); ?></span>
</div>
<div class="justify-between align-center d-flex">
<span class="car-price">$<?php echo number_format($car['price']); ?></span>
<a href="car_detail.php?id=<?php echo $car['id']; ?>" class="btn btn-outline">Details</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</section>
</main>
<?php include __DIR__ . '/includes/footer.php'; ?>