Im trying to add data to each of the array objects below.
[
{
"first_name":"Chris",
"surname":"Mowbray",
"id":"28"
},
{
"first_name":"Gary",
"surname":"Hume",
"id":"29"
},
{
"first_name":"Ian",
"surname":"Hume",
"id":"30"
}
]
this is the php that generates the array shown:
<?php
$selectedMatch = '( select max(event.match_id) from event)';
// need to update this match id based on usered slected on site
$getMatchPlayers = "select first_name,surname, id\n" . "from player, match_player\n" . "where player.id = match_player.player_id\n" . "and match_player.match_id = $selectedMatch";
$result = mysql_query($getMatchPlayers) or die(mysql_error());
$temp = array();
while ($row = mysql_fetch_assoc($result)) {
$temp[] = $row;
$player_id = $row['id'];
$AppResult = mysql_query(getApps($player_id)) or die(mysql_error());
$appearence = mysql_fetch_assoc($AppResult);
// fb($temp);
}
header('Content-Type: application/json');
echo json_encode($temp);
exit;
function getApps($playerid){
$getAppearances = "SELECT COUNT(player_id) \n" . "AS Appearances \n" . "FROM match_player\n" . "where player_id = $playerid\n";
return $getAppearances;
}
?>
im trying to add new data after 'id' of every object but everything that I have tried has added a new index to the array.
$appearence is what i want to add