prepare("SELECT * FROM elections WHERE id = ?"); $stmt->execute([$id]); $election = $stmt->fetch(); if (!$election) die("Election not found"); // Summary stats $vStmt = $pdo->prepare("SELECT COUNT(DISTINCT voter_id) FROM votes WHERE election_id = ?"); $vStmt->execute([$id]); $totalVoters = $vStmt->fetchColumn(); // Positions and results $positions = $pdo->prepare("SELECT * FROM positions WHERE election_id = ? ORDER BY sort_order ASC"); $positions->execute([$id]); $positions = $positions->fetchAll(); ?> Results: <?= htmlspecialchars($election['title']) ?>

- Results

Election

Total Ballots Cast

Results will be available once the election starts.

prepare(" SELECT c.*, u.name, (SELECT COUNT(*) FROM votes v WHERE v.candidate_id = c.id) as vote_count FROM candidates c JOIN users u ON c.user_id = u.id WHERE c.position_id = ? ORDER BY vote_count DESC "); $rStmt->execute([$pos['id']]); $results = $rStmt->fetchAll(); $posTotal = array_sum(array_column($results, 'vote_count')); ?> $res): $percent = $posTotal > 0 ? round(($res['vote_count'] / $posTotal) * 100, 1) : 0; $isWinner = ($index === 0 && $res['vote_count'] > 0); ?>
() Winner votes (%)