我用照片和描述製作了一個數據庫(php/mysql)。一切運作良好。我可以刪除整個記錄(4張圖片和說明),但不知道如何刪除只有一張圖片,以保持如3.預先感謝您的幫助從php刪除一條記錄用php
delete.php
<?php
// 2. Perform database query
$id = $photo["id"];
$safe_page_id = mysqli_real_escape_string($connection, $id);
$query = "DELETE FROM photographs ";
$query .= "WHERE id = {$id} ";
$query .= "LIMIT 1";
$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) == 1) {
// Success
$_SESSION["message"] = "product removed.";
redirect_to("list_photos_46.php");
echo "Success!";
} else {
// Failure
$_SESSION["message"] = "Failure.";
redirect_to("list_photos_46.php?page={$id}");
die("Database query failed. " . mysqli_error($connection));
}
?>
list_photos.php - 刪除所有照片和描述
<td><a href="delete_photo_2.php?id=<?php echo urlencode($row['id']); ?>"onclick="return confirm('are you sure? ');">{Delete}</a></td>
表格的結構/模式是什麼? – jeff
你的意思是你想刪除除一個以外的所有記錄? –
每張唱片有4張照片嗎? – MarcoS