php - 如何在php的for循环中显示图像?

标签 php html mysql

我在 mysql 数据库中有 5 个图像路径名称

现在我想在 for 循环的 slider 中显示它

include ('conn.php');

$select_path="select * from image_table";

$var=mysqli_query($conn,$select_path);

while($row=mysqli_fetch_array($var))
{
 $image_name=$row["name"];
 $image_path=$row["path"];
 $url=$image_path.$image_name;
}



echo' <div id="ninja-slider">
    <div class="slider-inner">
        <ul>';
            for($i=0;$i < $url;$i++){
               echo'<li>';
               echo'  <a class="ns-img" href="'.$url[$i].'"></a>
                <div class="caption">image 1</div>
               </li>';}

        </ul>
        <div class="fs-icon" title="Expand/Close"></div>
    </div>
</div>

for循环可以显示数据库中的列表吗?

最佳答案

不必要的多次循环并不是一个好习惯。我们应该避免程序中出现不必要的循环。

    include ('conn.php');

    $select_path="select * from image_table";

    $var=mysqli_query($conn,$select_path);
if(mysql_num_rows($var) > 0){
 echo' <div id="ninja-slider"><div class="slider-inner"><ul>';
    while($row=mysqli_fetch_array($var))
    {
     $image_name=$row["name"];
     $image_path=$row["path"];
     $url=$image_path.$image_name;
     echo '<li>';
     echo '<a class="ns-img" href="'.$url.'"><img src="'.$url.'" /></a>';
     echo '<div class="caption">image 1</div></li>';
    }

echo '</ul><div class="fs-icon" title="Expand/Close"></div></div></div>';
}

关于php - 如何在php的for循环中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50981733/

相关文章:

php - 将图像发送到服务器需要很多时间

HTML/CSS - 可滚动部分不适合页面。

html - mjpeg HTML5 视频不随 <video> 流式传输

javascript - 查找动态加载的 HTML 页面的标题

mysql - 如何通过插入到表中从mysql中的表中选择来添加额外的行?

php - mysql_real_escape_string 不起作用?

php - 错误:mysqli_stmt::bind_param():类型定义字符串中的元素数量与绑定(bind)变量的数量不匹配

php - 从 2 个不适用于 php mysql 的表中选择

mysql - 使用slave在内存中运行MySQL以实现持久化

php - 如何用PHP制作聊天室脚本?