Download

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


up