prepare("SELECT * FROM matches WHERE id = ?"); $stmt->execute([$match_id]); $match = $stmt->fetch(); if (!$match) { header('Location: matches.php'); exit; } // Fetch teams for the match $stmt = $pdo->prepare('SELECT t.name FROM teams t JOIN match_teams mt ON t.id = mt.team_id WHERE mt.match_id = ?'); $stmt->execute([$match_id]); $teams = $stmt->fetchAll(PDO::FETCH_COLUMN); // Fetch user's current vote $stmt = $pdo->prepare("SELECT vote FROM match_votes WHERE match_id = ? AND user_id = ?"); $stmt->execute([$match_id, $user_id]); $current_vote = $stmt->fetchColumn(); // Handle vote submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['vote'])) { $vote = $_POST['vote']; if ($current_vote) { // Update vote $stmt = $pdo->prepare("UPDATE match_votes SET vote = ? WHERE match_id = ? AND user_id = ?"); $stmt->execute([$vote, $match_id, $user_id]); } else { // Insert new vote $stmt = $pdo->prepare("INSERT INTO match_votes (match_id, user_id, vote) VALUES (?, ?, ?)"); $stmt->execute([$match_id, $user_id, $vote]); } // Refresh the page to show the updated vote status header('Location: match_view.php?id=' . $match_id); exit; } // Fetch all votes for this match to display who has voted $stmt = $pdo->prepare(' SELECT u.nickname, mv.vote FROM users u JOIN match_votes mv ON u.id = mv.user_id WHERE mv.match_id = ? ORDER BY mv.created_at DESC '); $stmt->execute([$match_id]); $votes = $stmt->fetchAll(); $match_date = new DateTime($match['match_datetime']); $formatted_date = $match_date->format('D, M j, Y '); $formatted_time = $match_date->format('g:i A'); ?>
Location:
Date:
Time:
0): ?>Teams: