i have succeeded after loots of effort to make a game that sends data to a database! yay for me. now well i need to retrieve that data and show them on a panel on gameover preferably in a scroll list. so for sending them i used UnityWebRequest.Post so naturally i tried using the UnityWebRequest.Get but i get internal errors.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class DataBaseGet : MonoBehaviour
{
public void GetData()
{
// A correct website page.
StartCoroutine(GetRequest("http://localhost/sqlconnect/showScoreboard.php"));
}
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
switch (webRequest.result)
{
case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError:
Debug.LogError(pages[page] + ": Error: " + webRequest.error);
break;
case UnityWebRequest.Result.ProtocolError:
Debug.LogError(pages[page] + ": HTTP Error: " + webRequest.error);
break;
case UnityWebRequest.Result.Success:
Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
break;
}
}
}
}
now i didint change anything on the script so i dont know if it can work that way. And my php file is straight from www3schools
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "nicknameget";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM players ORDER BY score DESC LIMIT 100";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["nickname"]. " - Name: " . $row["score"]. " " "
";
}
} else {
echo "0 results";
}
$conn->close();
?>
so i would deeply appreciate some help or a proper tutorial for doing so! thank you!