我使用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');
?>
答案 0 :(得分:4)
在每个循环中,您使用新值重置$tbl
的值。你必须像下面这样连接:
$tbl.= //rest of code
通过使用.
,您可以在PHP
中连接字符串。