I have this function in my controller:
public function estadisticas()
{
$conn = ConnectionManager::get('default');
$stmt = $conn->execute(
'SELECT c.nombre,
c.idcomplejo,
t.canchafk,
Count(*) AS cantidadturnos
FROM turno t
INNER JOIN usuario u ON u.idusuario = t.usuariofk
INNER JOIN cancha ca ON t.canchafk = ca.idcancha
INNER JOIN complejo c ON c.idcomplejo = ca.complejofk
INNER JOIN ciudad cc ON cc.idciudad=c.ciudadfk
WHERE u.escomplejo=0
AND cc.paisfk="1"
AND u.paisfk="1"
AND noasistio=0
AND fecha BETWEEN "2016-07-01" AND "2016-07-30"
GROUP BY canchafk');
$turnos = $stmt ->fetchAll('assoc');
$this->set('turnos',$turnos);
}
I need to make custom query because is dificult to make it like cakephp said.
So the result is for each “turnos”:
array(4) { ["nombre"]=> string(7) "Campnou" ["idcomplejo"]=> string(1) "1" ["canchafk"]=> string(1) "1" ["cantidadturnos"]=> string(2) "35" }
array(4) { ["nombre"]=> string(6) "Uñazo" ["idcomplejo"]=> string(1) "3" ["canchafk"]=> string(1) "6" ["cantidadturnos"]=> string(2) "29" }
Like this the area 17 more arrays.
When I do this:
<?php foreach ($turnos as $turno): ?>
<tr>
<br><?php var_dump($turno) ?></br>
<td><?= h($turno['idComplejo']) ?></td>
<td><?= h($turno['canchaFK']) ?></td>
<td><?= h($turno['cantidadTurnos']) ?></td>
</tr>
<?php endforeach; ?>
The rows are empty, but cakephp show me 19 empty row (the total rows of the query) .In phpmyadmin the query works perfect.
So… I have a problem try to showing the data from the json.
Thanks for help