[Solved] Loop data from query


Looping data from a query is a common task in programming. It is a process of iterating through a set of data and performing an action on each item in the set. This can be done in a variety of ways, depending on the language and the type of data being looped. In this article, we will discuss how to loop data from a query in SQL. We will look at the different types of loops available, how to use them, and some best practices for looping data from a query.



//Using a for loop

let query = “SELECT * FROM users”;

for (let row of query) {

//Using a while loop

let query = “SELECT * FROM users”;

let i = 0;
while (i < query.length) { console.log(query[i]); i++; }

Your json_decode() has a second parameter which determine the return type. By default, it will parse the JSON string into stdObject, while you access it using indexes which is wrong

$server = Json_Decode(File_Get_Contents("http://query.fakaheda.eu/"));
foreach($server->players_list as $player) { 
    echo '<span class="ipsGrid_span4">'.$player->name.'</span>'; 
    echo '<span class="ipsGrid_span4">'.$player->score.'</span>'; 
    echo '<span class="ipsGrid_span4">'.$player->time.'</span>'; 

To parse json string into array, use json_encode($jsonString, true)

$server = Json_Decode(File_Get_Contents("http://query.fakaheda.eu/"), true);
foreach($server['players_list'] as $player) { 
    echo '<span class="ipsGrid_span4">'.$player['name'].'</span>'; 
    echo '<span class="ipsGrid_span4">'.$player['score'].'</span>'; 
    echo '<span class="ipsGrid_span4">'.$player['time'].'</span>'; 

solved Loop data from query