32 lines
897 B
PHP
32 lines
897 B
PHP
<?php
|
|
// admin/includes/leaderboard_functions.php
|
|
|
|
/**
|
|
* Fetches leaderboard data by joining quiz_attempts and quiz_categories.
|
|
*
|
|
* @param int $limit The maximum number of records to return.
|
|
* @return array An array of associative arrays, each representing a leaderboard entry.
|
|
*/
|
|
function get_leaderboard_data($limit = 100) {
|
|
$db = db_connect();
|
|
$sql = "
|
|
SELECT
|
|
qa.player_name,
|
|
qc.name as category_name,
|
|
qa.score,
|
|
qa.total_questions,
|
|
qa.attempt_date
|
|
FROM
|
|
quiz_attempts qa
|
|
JOIN
|
|
quiz_categories qc ON qa.category_id = qc.id
|
|
ORDER BY
|
|
qa.score DESC, qa.attempt_date DESC
|
|
LIMIT :limit
|
|
";
|
|
$stmt = $db->prepare($sql);
|
|
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
?>
|