Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF - loop data in two columns layout

Tags:

foreach

php

tcpdf

Im using TCPDF, at the moment im a listing data in two columns using array_chunk which works fine. But i need data to be show in first columns and then second, see below:

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

This is the code:

<?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>

my second query(complex) if there are more than 30 rows i need to be able to use $pdf->AddPage(); and continues on the next page.

like image 963
TheDeveloper Avatar asked May 31 '15 12:05

TheDeveloper


1 Answers

TCPDF - support multicolumns, this is wat i used to solve my issue:

$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()

the code will add auto page break and continues to next page.

like image 119
TheDeveloper Avatar answered Sep 26 '22 13:09

TheDeveloper