-3

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 } ?>
ankit ingle
  • 213
  • 1
  • 5
  • 10

2 Answers2

0

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
  }
}
Tommy Jinks
  • 747
  • 6
  • 21
  • your code is correct ..but there is something wrong on that...i need when counter...reaches to 6....then do page break and restart counting again.......but your code only display 6 barcode on single page..and rest values are not displaying....on another page.... – ankit ingle Jun 08 '15 at 11:59
  • i need after if($curr_count <= $show) { //this line of code need else condition of page break and need to restart loop counting again from 1.. //show first 6 pieces of data } – ankit ingle Jun 08 '15 at 12:00
0
<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

csaw
  • 172
  • 11
  • see this [article](http://stackoverflow.com/questions/1630819/google-chrome-printing-page-breaks) – csaw Jun 09 '15 at 07:13