Hi i am working on a simple script where i would like to output the result of a given SQL query into JSON.
This is what i have so far:
$player = $this->game->getPlayer(5);
$leaderboard= $this->game->getLeaderboard(5);
$data = array(
'player' => array(
$player[0]->member_userunique, // USERNAME
$player[0]->score, // HIGHSCORE
$player[0]->memberid
),
'leaderboard' => array(
'score #1',
'score #2',
'score #3',
'score #4',
'score #5'
)
);
echo json_encode($data);
getPlayer(x) will return some information about the player. While getLeaderboard will get the top 5 records from the database. However, i would like to iterate each rows from the returned SQL result into the 'leaderboard' array.
I suppose i could use some brute-force by typing $leaderboard[0]->.... and so on but i would like to know the smarter way to do this.
Thanks for the help.
getLeaderboard(5)
the number of items to return, or is it the identifier op the player ?