duanlangwen9597 2015-08-27 11:03
浏览 64
已采纳

当我在while循环中从数据库调用blob图像时,我得到mysqli_fetch_array()期望参数1错误

when i run this code i get only one image and returns "mysqli_fetch_array() expects parameter 1 error", I want multiple images in my page. Here is my code,

<?php
$con=mysqli_connect("localhost","root","","education");

$result = mysqli_query($con,"Select * from ep_posts where id > '4' ");
$sql = "Select * from ep_posts where image<>''  order by ID ASC  ";

while ($row = mysqli_fetch_array($result)) {
    $name = $row['post_title'];
    $id = $row['ID'];
    $des = $row['des'];
    $des = substr($des, 0,35);  
    $link =  $siteurl."?p=".$id;    
    $sth = $con->query($sql);
    $result=mysqli_fetch_array($sth);

    $image =  '<img src="data:image/jpg;base64,'.base64_encode( $result['image'] ).'" height="150" width="150" >';

}
?>

help needed

  • 写回答

1条回答 默认 最新

  • doubi2228 2015-08-27 11:22
    关注

    Does this help.

    Remove the unnecessary second query and anything that was using it. Then just change the image tag to use data from the first query result.

    <?php
    $con=mysqli_connect("localhost","root","","education");
    
    $result = mysqli_query($con,"Select * from ep_posts where id > '4' ");
    
    // surely this is unnecessary
    //$sql = "Select * from ep_posts where image<>''  order by ID ASC  ";
    
    while ($row = mysqli_fetch_array($result)) {
        $name = $row['post_title'];
        $id = $row['ID'];
        $des = $row['des'];
        $des = substr($des, 0,35);  
        $link =  $siteurl."?p=".$id;    
    
        // so these are unnecessary
        //$sth = $con->query($sql);
        //$result=mysqli_fetch_array($sth);
    
        // so this need to use a column from first query result
        // so change $result['image'] to $row['image']
        $image =  '<img src="data:image/jpg;base64,'.base64_encode( $row['image'] ).'" height="150" width="150" >';
    
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下