HELP with VaRest and getting a json array

hi!
I really need help with outputting tables from the database,
Here is my PHP code as well as the bluprint code

PHP CODE



<?php
include("db_vars.php");
// Create a connection to the database
$link = new mysqli ($dbhost, $dbusername, $dbpassword, $dbname);

// Check connection to database
if ($mysqli->connect_error) 
{
    echo(json_encode(array('status'=>"Connection failed: " . $mysqli->connect_error)));
	die;
} 

/* here is where i am performing the query against the database to find the data i want 
select All ServerNames && ServerStatus from the statusCheck database and sort them by ID order*/ 

$query = "SELECT ServerName, ServerStatus FROM statusCheck ORDER by ID";  

//prepare the query statement
if ($stmt = mysqli_prepare($link,$query))
{

	//execute statment
	
	mysqli_stmt_execute($stmt);
	
	//bind the results of the query into variables
	
	mysqli_stmt_bind_result($stmt, $ServerName, $ServerStatus);
	
	//fetch the result values

        // here i am looping through the results as there is more than one row
	while (mysqli_stmt_fetch($stmt))
		
		{
				
                        // here i am creating an array to hold all the results of the query which is an array itself 
			$serverStatusArray = array(
			'serverName'=>$ServerName,
			'serverStatus'=>$ServerStatus
			);
        
		echo json_encode(array('ServerQueryResults'=>$serverStatusArray));
		
		}
					

                // finally we send the $serverStatusArray back to unreal and encode it as json
		
}
		
  /* close the statement */
    mysqli_stmt_close($stmt);


/* close the database connection */
mysqli_close($link);
		
?>

bandicam 2021-06-13 22-33-03-080


1 Like

up

any idea how to get an array with Varest?

You can get the response from Varest then use As Array, for each loop, As Object like this:

then from the As Object you can use Get String Field, Get Number Field…etc