Php 删除查询错误的While循环
我使用下面的代码删除具有特定albumId的图像,但删除不起作用,因为$row_getPicturesToBeDeleted['imageName']在循环中给出空结果Php 删除查询错误的While循环,php,mysql,while-loop,unlink,Php,Mysql,While Loop,Unlink,我使用下面的代码删除具有特定albumId的图像,但删除不起作用,因为$row_getPicturesToBeDeleted['imageName']在循环中给出空结果 // Get picture file names to be deleted $colname_getPicturesToBeDeleted = "-1"; if (isset($_GET['id'])) { $colname_getPicturesToBeDeleted = $_GET['id'];
// Get picture file names to be deleted
$colname_getPicturesToBeDeleted = "-1";
if (isset($_GET['id'])) {
$colname_getPicturesToBeDeleted = $_GET['id'];
}
mysql_select_db($database_eAlbum, $eAlbum);
$query_getPicturesToBeDeleted = sprintf("SELECT * FROM pictures WHERE albumId = %s",
GetSQLValueString($colname_getPicturesToBeDeleted, "int"));
$getPicturesToBeDeleted = mysql_query($query_getPicturesToBeDeleted, $eAlbum) or die(mysql_error());
$row_getPicturesToBeDeleted = mysql_fetch_assoc($getPicturesToBeDeleted);
$totalRows_getPicturesToBeDeleted = mysql_num_rows($getPicturesToBeDeleted);
// Delete pictures also physically
$dir = dirname(dirname(__FILE__));
do {
$imgToBeDeletedThumb = $dir."/server/php/files/thumbnail/".$row_getPicturesToBeDeleted['imageName'];
$imgToBeDeleted = $dir."/server/php/files/".$row_getPicturesToBeDeleted['imageName'];
unlink($imgToBeDeletedThumb);
unlink($imgToBeDeleted);
} while ($row_getPicturesToBeDeleted = mysql_fetch_assoc($getPicturesToBeDeleted));
header("listAlbums.php?d=s");
}
尝试在循环之前转储
$row\u getPicturesToBeDeleted
,是否为空?谢谢!问题是,正如您所说,我首先从数据库中删除图像,然后尝试通过从数据库中获取文件名数据来物理删除图像,该数据自我删除后为空:)