如何在php foreach循环中每次在bootstrap轮播中显示6个产品 我想在一张幻灯片中显示6个产品,下一张幻灯片有另外6个产品等等....... 怎么可能
我已经尝试过此代码,但不满足我的要求显示所有产品。
<?php
$data= $this->main->viewbook();
$r=0;
foreach ($data as $row){
if($r==0){ ?>
<div class="item active">
<?php } if($r%6==0) { ?>
<div class="item">
<?php } ?>
<div class="col-lg-2 col-xs-6 col-md-4 col-sm-6 thumbnails">
<div class="fff">
<a href="#"><img class="img-responsive" src="<?php echo base_url()?>assets/images/css.jpg" alt=""></a>
<strong>Praesent commodo Nibh Etiam Sem Nullam</strong><br>
<strong style=" color:#029f5b;"> <?php echo $row->BookID; ;?></strong><br>
Nullam Condimentum Nibh Etiam Sem no inquiry so cordial
<a class="" href="#">» Read More</a>
</div>
</div>
<?php $r++; if($r%6==0) { ?>
</div>
<?php } } ?>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
<a class="right carousel-control" href="#myCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
<!-- /.control-box -->
</div>
答案 0 :(得分:2)
我已更正您的代码,请在下方查看,我希望它能为您效劳。
<div class="item active">
<?php
$data= $this->main->viewbook();
$r=1;
foreach ($data as $row){
if($r%6==0) {
echo '</div><div class="item">';
}
?>
<div class="col-lg-2 col-xs-6 col-md-4 col-sm-6 thumbnails">
<div class="fff">
<a href="#"><img class="img-responsive" src="<?php echo base_url()?>assets/images/css.jpg" alt=""></a>
<strong>Praesent commodo Nibh Etiam Sem Nullam</strong><br>
<strong style=" color:#029f5b;"> <?php echo $row->BookID; ;?></strong><br>
Nullam Condimentum Nibh Etiam Sem no inquiry so cordial
<a class="" href="#">» Read More</a>
</div>
</div>
<?php $r++; } ?>
</div>