本文介绍了在 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:关键词]
发布评论