In this example, the pages will display continuously on the screen, but will have page breaks when printed.
<STYLE>
@media print {
DIV.PAGEBREAK {page-break-before: always}
}
</STYLE>
<?PHP
function PageFooter($pn) {
// echo some space
echo "Page $pn";
echo "</DIV>\n";
}
$result=mysql_query("SELECT * FROM mytable");
while ($row=mysql_fetch_array($result)) {
if ($items_on_page==0) {
$page_no++;
if ($page_no>1) $pageclass="CLASS='PAGEBREAK'"; // page break before start
echo "<DIV $pageclass>\n";
}
// echo data contained in $row
$items_on_page++;
if ($items_on_page==10) PageFooter($page_no);
$items_on_page=0;
}
// handle last page if necessary
if ($items_on_page>0) {
// echo some extra space
PageFooter($page_no);
}
?>