如何在php中每行显示四个图像,并且行可以是任意的
亲爱的朋友们,我有一组图片如何在php中每行显示四个图像,并且行可以是任意的,php,mysql,for-loop,Php,Mysql,For Loop,亲爱的朋友们,我有一组图片 <div class="img_team_container"> <div class="img_team_subcontain"> <div class="img_team"><a href="#" class="btn_1" title="Dining"></a></div> </div> </div>
<div class="img_team_container">
<div class="img_team_subcontain">
<div class="img_team"><a href="#" class="btn_1" title="Dining"></a></div>
</div>
</div>
我的问题是,如何在每行中显示四个图像,并且在php中,行可以是任意的否。我在代码中没有看到图像标记,而是使用模运算
<?
$perRow=4;
for($i=0;$i < count($myimages); $i++) {
echo '<img src="'.$myimages[$i].'"/>';
if(($i+1)%$perRow === 0) {
// we reched the end of the row, lets break
echo '<br/>';
}
}
?>
我在你的代码中没有看到图像标签,而是使用模运算
<?
$perRow=4;
for($i=0;$i < count($myimages); $i++) {
echo '<img src="'.$myimages[$i].'"/>';
if(($i+1)%$perRow === 0) {
// we reched the end of the row, lets break
echo '<br/>';
}
}
?>
假设您有一个图像数组
$images
:
<?php $i = 0; foreach($images as $image): ?>
<?php if($i === 0): ?>
<div class="row">
<?php endif; ?>
<?php echo sprintf('<img src="%s" />', $image['src']); ?>
<?php if($i === 4): $i = 0; ?>
</div>
<?php else: $i++; endif; ?>
<?php endforeach; ?>
假设您有一个图像数组
$images
:
<?php $i = 0; foreach($images as $image): ?>
<?php if($i === 0): ?>
<div class="row">
<?php endif; ?>
<?php echo sprintf('<img src="%s" />', $image['src']); ?>
<?php if($i === 4): $i = 0; ?>
</div>
<?php else: $i++; endif; ?>
<?php endforeach; ?>
这个问题让我有点困惑,你想要一个页面上有4个图像的行,并且可以有任意数量的行吗?您从何处获取这些图像的信息?作为第一步,尝试编写手动创建的HTML,例如两行。这让我们更好地了解您想要实现的目标以及您的问题所在。理想情况下,您甚至可以开始考虑如何在php中实现这一点,并使您的问题更加复杂!我有点被这个问题弄糊涂了,你想要一个页面上有4个图像的行,并且可以有任意数量的行吗?您从何处获取这些图像的信息?作为第一步,尝试编写手动创建的HTML,例如两行。这让我们更好地了解您想要实现的目标以及您的问题所在。理想情况下,您甚至可以开始考虑如何在php中实现这一点,并使您的问题更加复杂!