prepare( 'SELECT q.score, a.is_correct FROM submissions s JOIN answers a ON s.answer_id = a.id JOIN questions q ON s.question_id = q.id WHERE s.participant_id = ?' ); $score_stmt->execute([$participant_id]); $results = $score_stmt->fetchAll(PDO::FETCH_ASSOC); $total_score = 0; foreach ($results as $result) { if ($result['is_correct']) { $total_score += (int)$result['score']; } else { $total_score -= (int)$result['score']; } } return $total_score; } $participants_stmt = $pdo->query("SELECT id, nickname FROM participants"); $participants = $participants_stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($participants as $participant) { $leaderboard_data[] = [ 'nickname' => $participant['nickname'], 'score' => calculate_score($participant['id'], $pdo) ]; } // Sort by score descending usort($leaderboard_data, function($a, $b) { return $b['score'] <=> $a['score']; }); } // Using the same frontend style as index.php // I will read the content of index.php and extract the header and footer // For now I will just copy the style part ?> Classifica Quiz

Classifica Finale

$row): ?>
Rank Nickname Punteggio

La classifica non è stata ancora pubblicata. Torna più tardi!

Torna al Quiz