diff --git a/server/getData.php b/server/getData.php index 8e65e1f..4925869 100644 --- a/server/getData.php +++ b/server/getData.php @@ -1,5 +1,8 @@ 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 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); + + +if (isset($name)) { + $sql = "SELECT * FROM Sessie WHERE Naam=\"$name\" ORDER BY Score DESC LIMIT 10"; + $result = $conn->query($sql); + if ($result->num_rows > 0) { + // 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); + } + } else { + echo "0 results for requested name"; } -} else { - echo "0 results"; -} -echo $json; +} +else { + $sql = "SELECT * FROM Sessie ORDER BY Score DESC LIMIT 10"; + $result = $conn->query($sql); + if ($result->num_rows > 0) { + // 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); + } + } else { + echo "0 results"; + } + +} + + +echo $json; +$conn->close(); +?> \ No newline at end of file