[Solved] Loop data from query

Introduction

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.

Solution

//Solution

//Using a for loop

//Query
let query = “SELECT * FROM users”;

//Loop
for (let row of query) {
console.log(row);
}

//Using a while loop

//Query
let query = “SELECT * FROM users”;

//Loop
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/217.11.249.84:27408.feed"));
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/217.11.249.84:27408.feed"), 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