Skip to content Skip to sidebar Skip to footer

Have Dynamic Content Span Across Pages In Php

I have the following code that dynamically loads items in an invoice. I am looking for a way to adds excess items to a new page, and so on. I would like to limit the # of items o

Solution 1:

For your particular situation you could just indicate to dompdf to break the page, something along the lines of:

$itemCount = 0;
foreach ( $invoice['InvoiceDetail'] as$key=>$item){
    $itemCount++;
    $html .= '<tr style="border-bottom: 1px solid #ccc; line-height: 15px;">';

        /* snip */if ($itemCount % 20 == 0) {
            $html .= '<tr><td><div style="page-break-before: always;"></div></td></tr>';
        }

        $html .= '<td style="text-align: left"><h5>'.$itemNo.'</h5></td>';
        $html .= '<td style="text-align: left">'.$itemName.'</td>';
        $html .= '<td style="text-align: left">'.$price.'</td>';
        $html .= '<td style="text-align: left" width="10px">'.$quantity.'</td>';
        $html .= '<td style="text-align: right">'.$total.'</td>';

    $html .= '</tr>';
}

Dompdf does not yet recognize page break styling on table rows/cells. Otherwise it would make more sense to place the styling there.

Solution 2:

Does this help?

<?php$per_page = 20;

if ( $pagenum < 2 || !$pagenum ) {
    $limit_start = 0;
} else {
    $limit_start = (( $pagenum -1 ) * $per_page);
}

$sql = "select foo, bar, baz from table where $conditions limit $limit_start, $per_page";
$db->query( $sql ); //or whatever your method is// while statement to get data into $invoice array//foreach statement to display it//pagination links

Post a Comment for "Have Dynamic Content Span Across Pages In Php"