34915-vm/competitions.php
2025-10-14 07:40:18 +00:00

68 lines
2.8 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
// Fetch all competitions
$competitions = [];
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, title, description, start_date, end_date FROM competitions WHERE end_date > NOW() ORDER BY start_date ASC");
$competitions = $stmt->fetchAll();
} catch (PDOException $e) {
// In a real app, you'd log this error.
$error_message = "Sorry, we couldn't load competitions at this time.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Competitions - READY BUDDY</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<?php include 'includes/header.php'; ?>
<main class="container mt-5">
<div class="row">
<div class="col-md-12">
<h2 class="fw-bold">Available Competitions</h2>
<p>Join a competition and show your skills!</p>
<hr>
</div>
</div>
<div class="row">
<?php if (isset($error_message)): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php elseif (empty($competitions)): ?>
<div class="col-12">
<div class="alert alert-info">No upcoming competitions right now. Please check back later!</div>
</div>
<?php else: ?>
<?php foreach ($competitions as $comp): ?>
<div class="col-md-4 mb-4">
<div class="card h-100">
<div class="card-body d-flex flex-column">
<h5 class="card-title fw-bold"><?php echo htmlspecialchars($comp['title']); ?></h5>
<p class="card-text flex-grow-1"><?php echo nl2br(htmlspecialchars($comp['description'])); ?></p>
<p class="card-text"><small class="text-muted">Starts: <?php echo date('F j, Y, g:i a', strtotime($comp['start_date'])); ?></small></p>
<p class="card-text"><small class="text-muted">Ends: <?php echo date('F j, Y, g:i a', strtotime($comp['end_date'])); ?></small></p>
<a href="competition_details.php?id=<?php echo $comp['id']; ?>" class="btn btn-primary mt-auto">View Details</a>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</main>
<?php include 'includes/footer.php'; ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>