douxiong0668 2018-06-22 06:13 采纳率: 100%
浏览 164
已采纳

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

i had 5 images path and name in mysql database.

now i want to display that in a slider in for loop

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 loop can display a list from database?

  • 写回答

5条回答 默认 最新

  • doumen5895 2018-06-22 07:36
    关注

    can you tri this

    $servername = 'localhost';
    $username = 'root';
    $password = '';
    $dbname = 'image';
    $conn = new mysqli($servername,$username,$password,$dbname);
    if($conn->connect_error){
        die.("Connection failed : " .$conn->connect_error);
    }
    $select_path = 'select * from images';
    $var = mysqli_query($conn,$select_path);
    while ($row=mysqli_fetch_array($var))
    {
        $image_name = $row['image_name'];
        $image_path = 'images';
        $url = "$image_path".'/'."$image_name";
        echo'<div id="ninja-slider">
          <div class="slider-inner">
          <ul>';
        echo'  <a class="ns-img" href="'.$url.'"></a>
               <div class="caption">'.$url.'</div>
        </li>';
    }
    ?>
    </ul>
            <div class="fs-icon" title="Expand/Close"></div>
        </div>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络