dongzhimin2231 2015-06-08 11:10
浏览 23

php代码在每第n次迭代后中断页面

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 } ?>
  • 写回答

2条回答 默认 最新

  • dongzhuang2030 2015-06-08 11:28
    关注

    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
      }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?