views:

43

answers:

2

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.

+1  A: 

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/>';
 }
}
?>
Joe Hopfgartner
+1  A: 

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; ?>
prodigitalson