Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

php - Show two table headers in 1 loop

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

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

1 Reply

0 votes
by (71.8m points)
<?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; 
 ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...