this is my AdminUI.cs
using UnityEngine;
using TMPro;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine.Networking;
public class AdminUI : MonoBehaviour
{
public TextMeshProUGUI userPrefab; // TextMeshProUGUI prefab for user email and username
public Transform contentPanel; // Panel to which the TextMeshPro components will be attached
async void Start()
{
// Fetch user data from the database
string usersText = await Getusers.GetUsersText();
// Split the received text by newline character
string[] lines = usersText.Split('n');
// Display user data using TextMeshPro
foreach (string line in lines)
{
// Instantiate TextMeshPro component for user email and username
TextMeshProUGUI userText = Instantiate(userPrefab, contentPanel);
// Set the user email and username text
userText.text = line;
}
}
}
public static class Getusers
{
readonly static string SERVER_URL = "http://localhost:80/Cryppy";
public static async Task<string> GetUsersText()
{
string GET_USERS_URL = $"{SERVER_URL}/GetUsers.php";
UnityWebRequest req = UnityWebRequest.Get(GET_USERS_URL);
// Send the request asynchronously
var operation = req.SendWebRequest();
// Wait until the request is completed
while (!operation.isDone)
{
await Task.Delay(100); // You can adjust the delay time as needed
}
// Check for errors
if (req.result != UnityWebRequest.Result.Success)
{
Debug.LogError($"Error fetching users: {req.error}");
return null;
}
else
{
// Return the response text
return req.downloadHandler.text;
}
}
}
and this is the GetUser.php
<?php
// Connect to your database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cryppy_nightfall";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch user data
$sql = "SELECT email, username FROM user";
$result = $conn->query($sql);
// Check if any rows were returned
if ($result->num_rows > 0) {
$users = "";
// Output data of each row
while($row = $result->fetch_assoc()) {
// Concatenate email and username with a colon and line break
$user = $row["email"] . ":" . $row["username"] . "n";
$users .= $user;
}
// Return the string
echo $users;
} else {
echo "0 results";
}
$conn->close();
?>
in the website , the data displayed good
but in unity when lunch , the data display on each other so you can’t even read
tried to add
to the php
and tried n to the script
but not worked
btw am using scroll view , so this info should be dispalyed in UI screen