TCPDF仅显示循环中的一个HTML表

时间:2014-11-04 16:47:05

标签: php tcpdf

我使用TCPDF在PDF文件中成功显示HMTL表。

唯一的问题是它应该显示几个表,因为我使用FOREACH循环,但它只显示一个表。

请您查看下面的代码并帮我找出错误:

<?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');                    
?>

1 个答案:

答案 0 :(得分:4)

在每个循环中,您使用新值重置$tbl的值。你必须像下面这样连接:

$tbl.= //rest of code

通过使用.,您可以在PHP中连接字符串。