From 83f573873e39b2a662bc87f96cf28a4e7835e1c0 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 14:22:58 +0100 Subject: [PATCH] Post requested data into a json --- server/getData.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/server/getData.php b/server/getData.php index 4aa998e..8e65e1f 100644 --- a/server/getData.php +++ b/server/getData.php @@ -1,22 +1,26 @@ -connect_error) { die("Connection failed: " . $conn->connect_error); } -echo "Connected successfully"; - - - $sql = "SELECT * FROM Scores ORDER BY Score DESC LIMIT 10"; - $result = $conn->query($sql); +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} +//echo "Connected successfully"; +$sql = "SELECT * FROM Scores ORDER BY Score DESC LIMIT 10"; +$result = $conn->query($sql); if ($result->num_rows > 0) { - // output data of each row - while($row = $result->fetch_assoc()) { - echo "Name: " . $row["Naam"]. " -Score:" . $row["Score"]. "-Datum:" . $row["Datum"]. "
"; + // output data of each row and put them into a json array + while ($row = $result->fetch_assoc()) { + //echo "Name: " . $row["Naam"]. " -Score:" . $row["Score"]. "-Datum:" . $row["Datum"]. "
"; + $data[] = $row; + $json = json_encode($data); } - // $myJson = json_encode($result); - // echo $myJson; -} \ No newline at end of file +} else { + echo "0 results"; +} +echo $json; +