That did it! Thanks a lot.:D
It took me about 6 hours today to get through all the mistakes I was making. Kept putting the 3 parts of your code in the wrong place. I read lots of stuff online about alternating row colors and that helped a little. There are lots of ways to do the same thing I think.
It took me forever to finally realize I had to echo the div.
I have your code here in use and it is giving me a desired page break every 2 records.
I will paste my practice code here for any critique. Please let me know if you see anything out of place or unnecessary. Such as the use of } else { .
It was working either way.
using
if( ($rowCounter % 2) == 0 ){
// write out page break div
echo '<div style="page-break-after:always"></div>';
} else {
echo '<div style="page-break-after:avoid"></div>';
}
or just
if( ($rowCounter % 2) == 0 ){
// write out page break div
echo '<div style="page-break-after:always"></div>';
}
but I figured it wouldn't hurt to use the "page-break-after:avoid" too.
One area that puzzles me is that even without using a @media print in the style, it still gives the page break only when printed. (Which is what I want). But just for future reference, I tried to also give it a background color every other row and that didn't work. It ignored my color but the page break still works. And I guess you can't use a media type in an inline style?
Here is my test code. It repeats all my records and when printed, it gives me a dynamically generated page break after every 2 records.
<?php
$rowCounter = 1;
?>
<?php do { ?>
<div><?php echo $row_Recordset1['id']; ?></div>
<?php
if( ($rowCounter % 2) == 0 ){
echo '<div style="page-break-after:always"></div>';
} else {
echo '<div style="page-break-after:avoid"></div>';
}
$rowCounter++;
?>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<?php
mysql_free_result($Recordset1);
?>
Now to put into my working pages... :o
TroyD