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; ?>
Advertisement
Answer
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>