One festival has many stages. Multiple artists play at one stage.
Here is my Mysql result :
With that sql request, I'd like to create a json object with the following structure in PHP :
{
"name": "mainstage",
"artists": [
{
"name": "Gregori Klosman"
},
{
"name": "Tristan Garner"
},
{
"name": "Glow In The Dark"
},
{
"name": "Jaxx Da Fishworks"
}]
},
{
"name": "Dim Mak",
"artists" : [
{
"name": "Albin Myers"
}
]
}
I tried to do that with the following script but the structure is slightly different as I have an ID to identify the stage.
$stages = array();
while($result_stages = $query_stages -> fetch()) {
$artist = array("name" => $result_stages["artist_name"]);
array_push($stages[$result_stages["stage_id"]]["artists"], $artist);
}
echo json_encode($stages);
Any ideas ? I could make it with multiple mysql requests and php loops but I feel this is not the most proper way to do that. Thanks for your answer!