aboutsummaryrefslogtreecommitdiff
path: root/backend/rank.php
diff options
context:
space:
mode:
Diffstat (limited to 'backend/rank.php')
-rw-r--r--backend/rank.php36
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 ' }';
+
+?>