i have json:
[{"nombre":"example1","idcomplejo":"1","canchafk":"1","cantidadturnos":"35"}, {"nombre":"example2","idcomplejo":"3","canchafk":"6","cantidadturnos":"29"}, {"nombre":"example3","idcomplejo":"4","canchafk":"7","cantidadturnos":"6"}, {"nombre":"example4","idcomplejo":"5","canchafk":"8","cantidadturnos":"4"}, {"nombre":"example5","idcomplejo":"5","canchafk":"9","cantidadturnos":"2"}]
i wanna show in table html page, have error:
invalid argument supplied foreach()
this part of code getting error:
<table cellpadding="0" cellspacing="0"> <thead> <tr> <th>id complejo></th> <th># cancha></th> <th>cantidad turnos></th> </tr> </thead> <tbody> <?php foreach ($cantidadturnos $turno): ?> <tr> <td><?= h($turno->idcomplejo) ?></td> <td><?= h($turno->canchafk) ?></td> <td><?= h($turno->cantidadturnos) ?></td> </tr> <?php endforeach; ?> </tbody> </table>
the var_dump of cantidadturnos json put above. help
the json in form of javascript object. php cannot read needs parse json json_decode()
, this:
$cantidadturnos = json_decode('[{"nombre":"example1","idcomplejo":"1","canchafk":"1","cantidadturnos":"35"}, {"nombre":"example2","idcomplejo":"3","canchafk":"6","cantidadturnos":"29"}, {"nombre":"example3","idcomplejo":"4","canchafk":"7","cantidadturnos":"6"}, {"nombre":"example4","idcomplejo":"5","canchafk":"8","cantidadturnos":"4"}, {"nombre":"example5","idcomplejo":"5","canchafk":"9","cantidadturnos":"2"}]');
now $cantidadturnos
in form of array foreach
can work this:
foreach ($cantidadturnos $turno) { // }
Comments
Post a Comment