From cea71fdba9ba4ff9880af0dc6ae6631393d35152 Mon Sep 17 00:00:00 2001
From: LAMINO-HARO FERNANDO-JOEL <lamino@etu.unistra.fr>
Date: Sat, 13 May 2023 11:14:40 +0000
Subject: [PATCH] Upload New File by Lahad

---
 Database/Script_PHP/classement.php | 37 ++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Database/Script_PHP/classement.php

diff --git a/Database/Script_PHP/classement.php b/Database/Script_PHP/classement.php
new file mode 100644
index 000000000..24adfbe5b
--- /dev/null
+++ b/Database/Script_PHP/classement.php
@@ -0,0 +1,37 @@
+<?php
+$servername = "192.168.100.103";
+$username = "group1-1";
+$password = "Unistra2023#";
+$dbname = "bdd_ludo";
+
+try {
+    $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
+    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+}
+ catch(PDOException $e) {
+    echo "Connection failed: " . $e->getMessage();
+}
+
+$req = "SELECT * FROM Joueur ORDER BY score DESC, nbVictoire DESC, nbDefaite ASC";
+$res = $pdo->prepare($req);
+$res->execute();
+
+$retVal = array(); // Créez un tableau vide
+$rang = 1;
+
+while ($row = $res->fetch()) {
+    $retVal[] = array( // Ajoutez chaque résultat au tableau
+        "Rang" => $rang,
+        "Pseudo" => $row["pseudo"],
+        "Score" => $row["score"],
+    );
+    $rang++;
+}
+
+if(empty($retVal)) {
+    echo json_encode(array("response" => "Echec"));
+} else {
+    echo json_encode(array("response" => "Ok", "data" => $retVal)); // Envoyez le tableau en une seule fois
+}
+
+?>
\ No newline at end of file
-- 
GitLab