使用循环取消链接多个图像


Unlink Multiple images using a loop

我有一个代码,应该从mysql表中删除图像名称,并从服务器文件夹中删除实际图像。名称会从数据库中删除,但实际图像不会删除。以下是代码:

 $sql_queryy = "SELECT imImage FROM gimage WHERE imID = '$chkbxk'";
 $photoresultt = mysqli_query($connBiscup, $sql_queryy);
 //$row_album_images = mysqli_fetch_assoc($photoresultt);
 while ($row = mysqli_fetch_assoc($photoresultt)) { 
        unlink($target . $row[0]);
        unlink($targett . $row[0]);
 }

请帮忙

这是最初的代码。

for($i=0; $i<$N;$i++){
            $chkbxk = $_POST['checkbox'][$i];
            $sql_queryy = "SELECT imImage FROM gimage WHERE imID = '$chkbxk'";
            $photoresultt = mysqli_query($connBiscup, $sql_queryy);
            //$row_album_images = mysqli_fetch_all($photoresultt);
            foreach ($row_album_images as $row)
            {
                unlink($target . $row[0]);
                unlink($targett . $row[0]);
            }
}

但由于mysqlnd的问题,我改为while循环。

您需要将mysqli_fetch_assoc更改为mysqli_fetch_array

mysqli_fetch_assoc将返回关联数组(即['imImage'=>'img1']

mysqli_fetch_array将返回关联数组和数字数组(即[0=>'img1','imImage'=>'img1'])。

否则您可以重写循环体以使用关联数组。

while ($row = mysqli_fetch_assoc($photoresultt)) { 
        unlink($target . $row['imImage']);
        unlink($targett . $row['imImage']);
}