简体   繁体   中英

Codeigniter Print Domp PDF Page Break Limit 5 records per page In table foreach

I want to show only 5 records data per page in print pdf. This is my code :

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

Data is show correctly but any zero in my table in second and next page, like this image below : 在此处输入图片说明

how to use the code below correctly, ?

<?php if ($i % 5 === 1): ?>
                <p style="page-break-before: always;"></p>
            <?php endif; ?>
$array = array(1,2,3,4,5,6,7,8,9,10,11,12);
foreach ($array as $item){
  if ($item == 5) {
    break;
  }
  echo $item;
}

I have solved this, my table is look good now. Thank you :

在此处输入图片说明

I changed code like this :

<tbody>
        <?php 
            $i=1; 
            foreach($items as $row):
        ?>
        <tr>
            <td><?php echo $i++ ?></td>
            <td><?php echo $row->part_no?></td>
            <?php if ($i % 5 == 1) {
                    echo '<tr><td><div style="page-break-before: always;"></div></td></tr>';
                }?>
        </tr>
        <?php endforeach; ?>
     </tbody>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM