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

When i call blob image from data base in while loop I get mysqli_fetch_array() expects parameter 1 error

当我 运行 此代码时,我只得到一张图片,而 returns "mysqli_fetch_array() expects parameter 1 error",我想在我的页面中显示多张图片。 这是我的代码,

<?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" >';

}
?>

需要帮助

这有帮助吗。

删除不必要的第二个查询和任何使用它的东西。然后只需更改图像标签以使用第一个查询结果中的数据。

<?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" >';

}
?>