diff options
author | hitlerrip <git@hitler.rip> | 2025-07-29 21:25:30 +0200 |
---|---|---|
committer | hitlerrip <git@hitler.rip> | 2025-07-29 21:25:30 +0200 |
commit | 0dbbf0b26f24afa0c253e42682bba19ce7bd4cb6 (patch) | |
tree | 768b68b4240c7fe16c8b159a73aacf9ec0732935 /backend/rank.php | |
parent | cf81ced021761f14056808a99d5081bff9f3036c (diff) | |
download | hitler-clicker-0dbbf0b26f24afa0c253e42682bba19ce7bd4cb6.tar.gz hitler-clicker-0dbbf0b26f24afa0c253e42682bba19ce7bd4cb6.tar.bz2 hitler-clicker-0dbbf0b26f24afa0c253e42682bba19ce7bd4cb6.zip |
rank api
added api that lists all users, their teams and their personal
contributed clicks.
Diffstat (limited to 'backend/rank.php')
-rw-r--r-- | backend/rank.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/backend/rank.php b/backend/rank.php new file mode 100644 index 0000000..841127b --- /dev/null +++ b/backend/rank.php @@ -0,0 +1,36 @@ +<?php +/* hitler-clicker + * api for ranking users + * © 2025 hitler.rip <git@hitler.rip> + * licensed under AGPLv3-or-later; see LICENSE.md for more information + */ + +header('Content-Type: application/json; charset=UTF-8'); + +try { + $pdo = new PDO("mysql:host=127.0.0.1;dbname=hitlerclicker", "root", "aA1234Aa"); +} catch(PDOException $e) { + die('{ "status": "database offline" }'); +}; + +$query = $pdo->prepare("SELECT name, team, clicks FROM users WHERE name LIKE '%' ORDER BY clicks DESC"); +$query -> execute(); +$found = $query->fetchALL(PDO::FETCH_ASSOC); + +echo '{ '; + +$i = 0; +foreach($found as $user): + + $i++; + if ($i === sizeof($found)) { + echo " \"$user[name]\": { \"team\": \"$user[team]\", \"clicks\": \"$user[clicks]\" } "; + } else { + echo " \"$user[name]\": { \"team\": \"$user[team]\", \"clicks\": \"$user[clicks]\" }, "; + }; + +endforeach; + +echo ' }'; + +?> |