aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--backend/rank.php36
2 files changed, 40 insertions, 1 deletions
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 @@
+<?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 ' }';
+
+?>