Print PDF from 000webhost

0

Well I am trying to generate a pdf file, locally it is perfect, but when uploading it to this host that I am using tests I get the following error;

I consider that the error is not in the foreach, but at the moment of printing the data in the table td

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');
    
asked by Jonathan 08.05.2018 в 21:15
source

1 answer

1

The error consists of two parts:

  

Warning: Invalid argument supplied for foreach () in ...

It means that the variable to be traversed is not "recordable"

You can check it before like this:

if (is_array($sql) || is_object($sql)) {
foreach ($sql as $key=>$value) {

the second part of the error

  

TCPDF ERROR: Some data has already been output, can not send PDF file

indicates that the browser received something (text for example, the text of the previous error) before being able to send the header of the pdf

To know if the variable / object $sql has valid data place a var_dump($sql); before foreach and from there you can see what is happening, locally $sql have data and the hosting is empty .

    
answered by 08.05.2018 / 22:21
source