Reputation: 139
<div class="separator clear-left">
<p class="btn-add">
<i class="fa fa-shopping-cart"></i><a href="" class="hidden-sm">Add to cart</a></p>
<p class="btn-details">
<i class="fa fa-list"></i><a href="" class="hidden-sm">More details</a></p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
<?php
if ($counter == 8) {
break;
}
}
}
}
?>
</div>
</div>
<?php
}
The above code is part of my whole page. There is a problem about that is that when i using
foreach($result2 as $row2){
}
The page load without any problem , but it loop the same data, and if i change the follow code to
$row2 = $result2->fetch_assoc();
The whole page stopped working .(code error)
So what should i change about it ?
after edited , the page is showing all product now instead of 8 product
Upvotes: 0
Views: 93
Reputation: 1966
Use your printing code inside the foreach
loop.
<?php
$counter = 0;
foreach($result2 as $row2){
$counter++;
if($counter =< 8){
continue;
}
?> // closing php tag
<div class="col-sm-3">
<div class="col-item">
<div class="photo">
<img src="/image/<?php echo $row2['image']; ?>" class="img-
responsive" alt="a"/>
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>
<?php echo $row2['name'];?>
<?php
$counter++;}
?> //Closing the php tag and foreach loop
Upvotes: 2