【发布时间】:2021-12-12 10:40:05
【问题描述】:
我想在打印 pdf 中每页仅显示 5 条记录数据。这是我的代码:
<table border="1" width="100%" cellpadding="10">
<thead>
<tr>
<th>No</th>
<th>Part No</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
$i=1;
foreach($items as $row):
?>
<tr>
<td><?php echo $i++ ?></td>
<td><?php echo $row->part_no?></td>
<td><?php echo $row->price ?></td>
</tr>
<?php if ($i % 5 === 1): ?>
<p style="page-break-before: always;"></p>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td><?php echo $total ?></td>
</tr>
</tfoot>
</table>
数据显示正确,但在第二页和下一页的表格中显示任何零,如下图所示:
如何正确使用下面的代码,?
<?php if ($i % 5 === 1): ?>
<p style="page-break-before: always;"></p>
<?php endif; ?>
【问题讨论】:
-
你到底想要什么?
-
这个位置的
tbody中不能有p,这是无效的HTML。您需要将此应用于您的tr元素之一。 -
如何用正确的代码让它好看?
标签: php html css codeigniter