Apologies if this has answers using a different terminology; I've been searching around but can't find an answer to this question.
I'm trying to add results from an SQL query as a nested array within another array. The parent array looks like this:
$room=[
"id" => $roomID,
"name" => $roomName,
"desc" => $roomDesc,
"tracks" => [
//SQL Results here!
track {
//Track ID,
//Track Name,
//Track Artist,
//Track URL,
},
track {
//Track ID,
//Track Name,
//Track Artist,
//Track URL,
},
]
];
I'm not sure how to add a sub-array of tracks into this array however. Currently I'm creating an array like this:
$rows = array();
//SQL Call logic here
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$row_array['id'] = $row['id'];
$row_array['track_name'] = $row['track_name'];
$row_array['track_artist'] = $row['track_artist'];
$row_array['track_url'] = $row['track_url'];
array_push($rows,$row_array);
}
print_r(json_encode($rows));
} else {
echo "Error: Tracks not found";
return;
$conn->close();
die();
}
I'm looking to have each SQL result as a "track" object within the "tracks" array in $room
, I just don't know how!