From 0dbbf0b26f24afa0c253e42682bba19ce7bd4cb6 Mon Sep 17 00:00:00 2001 From: hitlerrip Date: Tue, 29 Jul 2025 21:25:30 +0200 Subject: rank api added api that lists all users, their teams and their personal contributed clicks. --- README.md | 5 ++++- backend/rank.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 backend/rank.php diff --git a/README.md b/README.md index f2632ed..0e2e88b 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,12 @@ curl -X POST -d '{ "key": "value" }' http://localhost:8000/yourapifile.php ## To-Do +### Backend + - add api that returns a specific users clicks -- add api that returns all users and their respective clicks and teams - add name and password change - add anonymous clicking for a team +### Frontend + - frontend 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 @@ + + * 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 ' }'; + +?> -- cgit v1.2.3