Reputation: 413
Dear Friends I have a Div of Images.
<div class="img_team_container">
<div class="img_team_subcontain">
<div class="img_team"><a href="#" class="btn_1" title="Dining"></a></div>
</div>
</div>
My question is that How can I show four images per row and rows can be of any no with php.
Upvotes: 0
Views: 1607
Reputation: 60413
Assuming you have a array $images
of images:
<?php $i = 0; foreach($images as $image): ?>
<?php if($i === 0): ?>
<div class="row">
<?php endif; ?>
<?php echo sprintf('<img src="%s" />', $image['src']); ?>
<?php if($i === 4): $i = 0; ?>
</div>
<?php else: $i++; endif; ?>
<?php endforeach; ?>
Upvotes: 2
Reputation: 29866
well i dont see an image tag in your code but use modulo arithmetics.
<?
$perRow=4;
for($i=0;$i < count($myimages); $i++) {
echo '<img src="'.$myimages[$i].'"/>';
if(($i+1)%$perRow === 0) {
// we reched the end of the row, lets break
echo '<br/>';
}
}
?>
Upvotes: 1