gpt4 book ai didi

php - TCPDF - 以两列布局循环数据

转载 作者:可可西里 更新时间:2023-10-31 23:19:20 25 4
gpt4 key购买 nike

我正在使用 TCPDF,目前我使用 array_chunk 在两列中列出数据,效果很好。但我需要数据显示在第一列,然后是第二列,见下文:

Currently:
1 2
3 4
5 6
7 8
9 10
Should be:
1 6
2 7
3 8
4 9
5 10

这是代码:

<?php   $array = range(1, 50);?>
<table nobr="true" cellpadding="2">
<?php foreach (array_chunk($array, 2) as $a) { ?>
<tr>
<?php foreach ($a as $array_chunk) { ?>
<td><?php echo $array_chunk; ?></td>
<?php
} ?>
</tr>
<?php } ?>
</table>

我的第二个查询(复杂)如果有超过 30 行我需要能够使用 $pdf->AddPage();并在下一页继续。

最佳答案

TCPDF - 支持多列,这是我用来解决问题的方法:

$pdf->AddPage();
$pdf->resetColumns();
$pdf->setEqualColumns(2, 84); // KEY PART - number of cols and width
$pdf->selectColumn();
$content =' loop content here';
$pdf->writeHTML($content, true, false, true, false);
$pdf->resetColumns()

代码将添加自动分页符并继续到下一页。

关于php - TCPDF - 以两列布局循环数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30557227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com