Well I'm trying to generate a pdf file, locally it does it perfectly, but when uploading it to this host that I'm using for testing I get the following error;
I consider that the error is not in the foreach, but when printing the data in the tabletd
foreach($sql as $key => $value){ //Linea 71 supuesto error
$html1= <<<EOF
<table style="font-size:13px; padding:5px 10px; border: 1px solid #666;" align="center">
<tr>
<td style="border-right: 1px solid #666; border: 1px solid #666;">$value[nombres]</td>
<td style="border-right: 1px solid #666; border: 1px solid #666;">$value[apellidos]</td>
<td style="border-right: 1px solid #666; border: 1px solid #666;">$value[correo]</td>
<td style="border-right: 1px solid #666; border: 1px solid #666;">$value[usuario]</td>
<td style="border-right: 1px solid #666; border: 1px solid #666;">$value[privilegio]</td>
</tr>
</table>
EOF;
$pdf->writeHTML($html1, false, false, false, false, ''); //Salida PDF
} //Cierre foreach
$pdf->Output('reporte.pdf', 'I');
The error consists of two parts:
It means that the variable to be traversed is not "traversable"
you can check it before like this:
the second part of the error
indicates that the browser received something (text for example, the text of the previous error) before it could send the headers of the pdf
To know if the variable/object
$sql
has valid data, place avar_dump($sql);
beforeforeach
and from there you will be able to see what is happening, it may$sql
have data locally and it is empty on the hosting.