I need to send a multidimensional array in JSON starting from a MySQL query .
The SQL Query is a LEFT JOIN such as this:
SELECT `TEAM`.`ID` AS TEAM_ID, `TEAM`.`NAME` AS TEAM_NAME, `TEAM_PLAYER`.`ID` AS TEAM_PLAYER_ID, `TEAM_PLAYER`.`NAME` AS TEAM_PLAYER_NAME FROM `TEAM_PLAYER`
LEFT JOIN `TEAM` ON `TEAM_PLAYER`.`TEAM_ID` = `TEAM`.`ID`
this query however returns a flat array with repeating columns such as
1 RED SOCKS 34 jOHN DOE
1 RED SOCKS 39 MICHAEL CAGE
2 VELVET 94 ARIA SAM
which is both redundant to send over the internet and cumbersome to treat.
I would like instead to get a JSON such as:
"0": {TEAM_ID : 1, TEAM_NAME : "RED SOCKS", "0": {TEAM_PLAYER_ID: 34, TEAM_PLAYER_NAME: JOHN DOE}, "1": {TEAM_PLAYER_ID: 39, TEAM_PLAYER_NAME: MICHAEL CAGE} },
"1": {TEAM_ID : 2, TEAM_NAME : "VELVET", "0": {TEAM_PLAYER_ID: 94, TEAM_PLAYER_NAME: ARIA SAM}
to return with a call to json_encode()
is there some proper way to do it?