EducateYourself
EducateYourself

Reputation: 979

TCPDF displays only one HTML table from the loop

I successfully display HMTL table in PDF file using TCPDF.

The only problem is that it should display several tables because I use FOREACH loop but it displays only one table.

Could you please check my code below and help me to find my mistake:

<?php tcpdf();
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$title = "pdf";
$obj_pdf->SetTitle($title);
//blablabla
$obj_pdf->setFontSubsetting(false);
$obj_pdf->AddPage();
ob_start();

foreach($results as $row){                  
                    $first = $row->first;                   
                    $second = $row->second;                     
                    $third = $row->third;                       
$tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1"> 
<tr>
    <td> $first </td>    
</tr> 
<tr>    
    <td>$second </td>
</tr>
<tr>
    <td> $third </td>     
</tr>
</table>
EOD;
}

ob_end_clean();
$obj_pdf->writeHTML($tbl, true, false, true, false, '');
$obj_pdf->Output('output.pdf', 'I');                    
?>

Upvotes: 2

Views: 2587

Answers (1)

Ali MasudianPour
Ali MasudianPour

Reputation: 14459

In each loop you reset the value of $tbl with new value. You must do concatenation like below:

$tbl.= //rest of code

By using . you can concatenate strings in PHP.

Upvotes: 4

Related Questions