Php 添加<;br/>;在一个变量中每2个来自mysql的图像
我试图让这段代码在总共有4个图像的情况下,在2个图像之后插入一个换行符。下面列出的代码在显示所有图像后添加换行符,而不是在两个图像后。有人能帮我吗Php 添加<;br/>;在一个变量中每2个来自mysql的图像,php,Php,我试图让这段代码在总共有4个图像的情况下,在2个图像之后插入一个换行符。下面列出的代码在显示所有图像后添加换行符,而不是在两个图像后。有人能帮我吗 $images = ""; $i = 0; while ($info = mysqli_fetch_array($imglist)) { $style = $info['Style']; $imgpath = $info['ImgPath']; $standardimg = $info['StandardImg']; $colorna
$images = "";
$i = 0;
while ($info = mysqli_fetch_array($imglist)) {
$style = $info['Style'];
$imgpath = $info['ImgPath'];
$standardimg = $info['StandardImg'];
$colorname = $info['ColorName'];
$smallimgwidth = $info['SmallImgWidth'];
$images = $images.
"<img src='$imgpath/$standardimg-Small.jpg'
alt = '$mill $style - $colorname'
title = '$mill $style - $colorname'
style = 'min-width:35px; max-width:$smallimgwidthpx;' / > ";
if (mysqli_num_rows($imglist) == 4) {
if ($i != 0 && $i % 2 == 1) {
echo '<br />';
}
}
$i++;
}
$images=”“;
$i=0;
而($info=mysqli\u fetch\u数组($imglist)){
$style=$info['style'];
$imgpath=$info['imgpath'];
$standardimg=$info['standardimg'];
$colorname=$info['colorname'];
$smallimgwidth=$info['smallimgwidth'];
$images=$images。
" ";
if(mysqli_num_rows($imglist)==4){
如果($i!=0&&$i%2==1){
回声“
”;
}
}
$i++;
}
更改
echo '<br />';
echo'
';
到
$images=$images'
;
就这样
我很少解释:您没有将br输出与图像输出“分组”,因为一个进入变量(图像),另一个立即显示(br)。**问题** 您正在动态构建标记,但在此过程中,您将分别添加
标记 解决方案 将标签添加到正在生成的标签字符串中 代码
$images = $images . '<br />';
$images=$images'
;
代替
echo '<br />';
echo'
';
这很有效。非常感谢你!如何在您的评论中添加复选标记而不是答案?
echo '<br />';