I'm trying to create an array of a mysql query and I'm going crazy. That query returns me several machines by centers. And I want to make an array with the centers that have and within each center the different machines
foreach ($maquinas as $row){
$centros['centros'][$row->id_centro] = $row->nombre;
}
So far, well, but I do not know how to get inside each center to create an array with the different machines.
This is the mysql query:
SELECT maquinas.*, centro.* from maquinas JOIN centro_maquinas ON centro_maquinas.id_maquina = maquinas.id_maquina JOIN centro ON centro.id_centro = centro_maquinas.id_centro ORDER BY id_centro
Returns several rows each with the id of the center, the id of the machine ...