I am printing barcode on a page...from database...
I need to display only 6 barcode coupon on single page.
After that I need to break page.....and continue...till last row.
below is my code...but i cannot understand how to count and break page after every 6th row.
plz help me..
<?php foreach($data as $row) { ?>
<table border="1px solid #666" summary="" width="48%" class="pos_fixed1">
<thead>
<tr>
<td>Receipt</td>
<td><?php echo htmlspecialchars($row['receipt_no']); ?></td>
<td>Coupon</td>
<td><?php echo htmlspecialchars($row['coupon']); ?></td>
</tr>
</thead>
</table>
<?php } ?>
Like mentioned in the comments, a good way around your problem would be to use pagination, as it means that you are giving users a way to still see this information. For quite a basic tutorial on this, I suggest looking here.
Alternatively, if you really need to use the approach you mentioned then something below may help you:
$count = count($data); //size of your array
$curr_count = 0; //will be used to increment each turn of loop
$show = 6; //how many pieces of data you want to show
foreach($data as $row) {
$curr_count++;
if($curr_count <= $show) {
//show first 6 pieces of data
} else if ($curr_count == $count) {
//show last data
} else {
//do your page break
}
}
<STYLE TYPE="text/css">
P.breakhere {page-break-before: always}
.tblBRCD{border="1px solid #666" summary="" width="48%"}
</STYLE>
<table class="pos_fixed1 tblBRCD">
<?php
$count==0;
foreach($data as $row)
{
echo '<tr><td>Receipt</td><td>'. htmlspecialchars($row['receipt_no']) .'</td>
<td>Coupon</td><td>'. htmlspecialchars($row['coupon']) .'</td></tr>';
$count++;
if($count==6){echo '<P CLASS="breakhere">'; $count=0;}
}
?>
</table>
see this article for further reference