" name="b1" width-6ren">
gpt4 book ai didi

php - 如何将连续的图像数量限制为三个?

转载 作者:太空狗 更新时间:2023-10-29 13:06:46 24 4
gpt4 key购买 nike

我正在将数据库中的图像填充到表格中,如何将图像限制为每行三个?

<table border="0" align="center" height="25%" width="25%"  >
<tr><td align="center" width="50px" bgcolor="#4b2d0e"><strong><font color="#FFFFFF">Friend List</font></strong></td></tr>
<? foreach($Selected as $row)
{
$value = $row['dPath'];
$imgp = base_url()."images"."/".$value;
?>
<tr><td bgcolor="#999999">
<strong ><?=$row['dFrindName'].'</br>';?></strong>
<? if($value!="") { ?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="<?=$imgp ?>" name="b1" width="90" height="80" border="0"/></a><br>
<? } else { ?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="../images/us.png" width="90px" height="80px"></a>
<? }?>
</td></tr>
<? }}?>
</table>

这是我的 table

最佳答案

<?php 

$x=0;

foreach($Selected as $row){

if($x%3 == 0)
echo '<tr>';

$value = $row['dPath'];
$imgp = base_url()."images"."/".$value;
?>

<td style="background-color:#999999;">
<strong ><?=$row['dFrindName'].'</br>';?></strong>

<?php if($value!="") {?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="<?=$imgp ?>" name="b1" width="90" height="80" border="0"/></a><br>
<?php } else { ?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="../images/us.png" width="90px" height="80px"></a>
<?php }?>
</td>
<?php
if($x%3 == 0)
echo '</tr>';
x++;
}

if(($x-1)%3 != 0)
echo '</tr>'; //Prints out the last '<tr>' if one isn't printed.
?>

您需要使用带有模数运算符的 if

关于php - 如何将连续的图像数量限制为三个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3074468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com