Skip to content
Snippets Groups Projects
Commit cea71fdb authored by LAMINO-HARO FERNANDO-JOEL's avatar LAMINO-HARO FERNANDO-JOEL
Browse files

Upload New File by Lahad

parent 7f266a14
Branches
Tags
No related merge requests found
<?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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment