PROBLEM SOLVED SEE LAST POST IF YOU ARE INTERESTED IN THE ANSWER . THANKS
k i deleted my other thread because i think i didn’t explain myself clearly and people were getting confused when they were trying to answer me.
so what i am trying to do is query my statusCheck database, which contains all the information stored about my servers and then send the result of this query back to unreal via json so that i can then use this data to drive my blueprint logic and then also use this data to populate a UMG widget that will show the clients all the server information
this is my database at the moment it is very basic for testing.
So for this example i want to query the database and return the status of just 1 server (Lobby) and see if it is online or not. so i wrote my php script like this
<?php
// Create connection
$link = new mysqli ($servername, $username, $password, $dbname);
// Check connection
if ($mysqli->connect_error)
{
echo(json_encode(array('status'=>"Connection failed: " . $mysqli->connect_error)));
die;
}
// select Lobby Status from the statusCheck database
$query = "SELECT ServerStatus FROM statusCheck WHERE ServerName ='Lobby'";
if ($stmt = mysqli_prepare($link,$query))
{
//execute statment
mysqli_stmt_execute($stmt);
//bind variables
mysqli_stmt_bind_result($stmt, $ServerStatus);
//fetch values
while (mysqli_stmt_fetch($stmt))
{
echo json_encode(array('ServerStatus'=>$ServerStatus));
}
}
/* close statement */
mysqli_stmt_close($stmt);
/* close connection */
mysqli_close($link);
?>
now this works perfectly , when i run the script i get the following json
{“ServerStatus”:“offline”}
so i know that in this case the lobby server is offline because i specifically selected the Lobby server in the query.
inside unreal i setup a test to see if it works like so
and as expected the result is
now the problem is when i alter my query to try and return **ALL **the results from the database. it doesn’t work.
php code is now
<?php
// Create connection
$link = new mysqli ($servername, $username, $password, $dbname);
// Check connection
if ($mysqli->connect_error)
{
echo(json_encode(array('status'=>"Connection failed: " . $mysqli->connect_error)));
die;
}
// select All ServerNames && ServerStatus from the statusCheck database and sort them by ID order
$query = "SELECT ServerName, ServerStatus FROM statusCheck ORDER by ID";
if ($stmt = mysqli_prepare($link,$query))
{
//execute statment
mysqli_stmt_execute($stmt);
//bind variables
mysqli_stmt_bind_result($stmt, $ServerName, $ServerStatus);
//fetch values
while (mysqli_stmt_fetch($stmt))
{
echo json_encode(array('ServerName'=>$ServerName, 'ServerStatus'=>$ServerStatus));
}
}
/* close statement */
mysqli_stmt_close($stmt);
/* close connection */
mysqli_close($link);
?>
which outputs the following json
{“ServerName”:“Lobby”,“ServerStatus”:“offline”}{“ServerName”:“Server1”,“ServerStatus”:“online”}
but it is not valid json and so wont work in unreal.
so does anyone know how i would solve this problem so that i can do logic like this
so here you can see the logic im trying to do is
if (serverName == Lobby && ServerStatus == offline)
{
// call custom function to do stuff
}
of course i would like to do this for all of my servers.
So please if anyone can help on how to do this i would be very happy.
at the moment the work around i have is to have a separate PHP script for every single server and just query them one at a time, which is not too bad as the database is only little but obviously this would soon become a nightmare if i had loads of servers.
Im sure it is possible i just need a little help figuring out how .
I think I need to put the results of the query into an array and then echo the array
but not sure how to then put each result into a field so that i can still use the field nodes in unreal as these seem to only take a single value??
So I end up with something like this
Row 1 in database query result is
Field ServerName = Lobby
Field ServerStatus = offline
Row 2 in database query result is
Field ServerName = Server1
Field ServerStatus = offline
Etc
thankyou