Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem to show photos with two table headings(th) in one for loop. I have a array of 8 photos now I want to show 4 photos in one table and then 4 other photos in next table with one more heading, see my attached screenshot,I'm using forloop but not success,it is showing in one table not two. how I can do this I have a array of 8 photos and want to show something like screenshot.

My code:

  <table class="table table-bordered" style="float:left; width:400px;">  
    <thead>  
      <tr>  
        <th>Private</th>  
        <th>Public</th>  
        <th>Photos</th>              
      </tr>  
    </thead>  
    <?php foreach(Yii::app()->session['photos'] as $imageKey=>$image):?>


    <tbody>  
      <tr>  
    <td><input type="radio"  name="month1" value="1month" /></td>  
     <td><input type="radio" name="month1" value="1month"  /></td>  
     <td><div class="span2" id="photo_<?php echo $imageKey;?>"><a href="#"><img src="<?php echo Yii::app()->createAbsoluteUrl('renterphotos');?>/<?php echo $image;?>"></a></div></td>            
      </tr>  

        </tbody>  
<?php endforeach; ?>

  </table>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
170 views
Welcome To Ask or Share your Answers For Others

1 Answer

<?php
$count=1;
$total_photos=count(Yii::app()->session['photos']);
 foreach(Yii::app()->session['photos'] as $imageKey=>$image):
   if($count%4==1):      
 ?>
<table class="table table-bordered" style="float:left; width:400px;">  
<thead>  
  <tr>  
    <th>Private</th>  
    <th>Public</th>  
    <th>Photos</th>              
  </tr>  
</thead>  
<tbody>  
  <?php endif; ?>

  <tr>  
<td><input type="radio"  name="month1" value="1month" /></td>  
 <td><input type="radio" name="month1" value="1month"  /></td>  
 <td>
<div class="span2" id="photo_<?php echo $imageKey;?>"><a href="#"><img src="<?php echo Yii::app()->createAbsoluteUrl('renterphotos');?>/<?php echo $image;?>">  </a></div></td>            
  </tr>  
<?php if($count%4==0 || $count==$total_photos):   ?>
    </tbody>  
  </table>
<?php endif; ?>
<?php 
  $count++;
  endforeach; 
 ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...