[eluser]georgeedwards[/eluser]
Hello everyone! Hope you're all well..
Could anyone help me with a little bit of a traditional PHP/logic problem? (my brain is really not working today).
Situation is, I have a client project in CI that prints out load sheets for lorries (they are a delivery firm). I.e. there will be several "delivery runs" a day, then each run will have several deliveries for that day. Traditional nested foreach type thing. There is a view that does this and it is very basic. But I want to try and smarten it up with a pagination/page count e.g. Page 1 of 3 etc.
Put simply, it's like this (code is stripped down completely for simplicity):
Code:
<?php foreach ($runs as $run): ?>
<?php $total_pages = ceil(count($run['deliveries'])/5);?>
<h1>Runsheet #<?=$run['id']?> (<?=$total_pages?> sheets)</h1>
Driver name: <?=$run['firstname']?> <?=$run['lastname']?>
Run totals: <?=$run['totalitems']?> plts at <?=$run['totalweight_kg']?>kg
<?php $i = 0; ?>
<?php foreach($run['deliveries'] as $delivery): ?>
<?php $i++; ?>
<hr/>
// echo out delivery information here...
<hr/>
<?php if ($i % 5 == 0) echo '<div style="page-break-after:always;></div>'; ?>
<?php endforeach; ?>
<?php endforeach; ?>
As you can see I've managed to set it so that only 5 deliveries get shown per page, and it breaks after that. On that basis, I've also used ceil() to work out how many pages there will be if there is 5 deliveries on each.
But I can't for the life of me workout how to set either a header or a footer saying "Page 1 of 3 / Page 2 of 3" and so on through the pages.
Anyone have any ideas to point me in the right direction?
Thanks for your time