在 1 个循环中显示两个表标题

编程入门 行业动态 更新时间:2024-10-23 08:40:33
本文介绍了在 1 个循环中显示两个表标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我无法在一个 for 循环中显示带有两个表格标题(th)的照片.我现在有一组 8 张照片,我想在一张表中显示 4 张照片,然后在下一张表中显示另外 4 张照片,还有一个标题,请参阅我附加的屏幕截图,我正在使用 forloop 但没有成功,它显示在一张表中不是两个.我怎么能做到这一点我有 8 张照片的数组,想要显示类似屏幕截图的内容.

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.

我的代码:

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

推荐答案

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

这篇关于在 1 个循环中显示两个表标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:21:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047343.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   标题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!