【问题标题】:Show two table headers in 1 loop在 1 个循环中显示两个表头
【发布时间】:2013-11-29 20:14:40
【问题描述】:

在一个 for 循环中显示带有两个表格标题的照片时遇到问题。 我有 8 张照片的数组,现在我想在一张桌子上显示 4 张照片,然后在下一张桌子上显示另外 4 张照片,还有一个标题,请参阅我随附的屏幕截图,我正在使用 forloop 但没有成功,它显示在一张桌子上不是两个。我该怎么做?我有一组 8 张照片,想展示一些类似截图的东西。

我的代码:

  <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>

【问题讨论】:

  • 提示一下,可以写成=$imageKey;?>
  • 当我替换 =$imageKey;?> 图片不显示。我的系统不支持这个php标签,
  • 确实可以这样。

标签: php yii


【解决方案1】:
<?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; 
 ?>

【讨论】:

  • 谢谢!你的回答是解决我的问题,现在我在两张桌子外面看到一行。我如何把它放在桌子里?
  • 我在那里检查了为什么如果我有 7 张照片然后在桌子外有 1 行会发生这种情况。请检查一下!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多