【发布时间】:2017-06-25 00:57:34
【问题描述】:
当用户点击图片时,如何从数据库中删除图片。
我有一个输入字段,将图像链接放入一个表格中,每个链接用逗号分隔..
<input id="galleryImgs" type="file" multiple="multiple" name="files[]">
这就是图像数组在 post_gallery_img 数据库列中的外观。
Img1.jpg,Img2.jpg,Img3.jpg,Img4.jpg,
我正在从数据库中调用图像并使用此 php 代码显示它们。
$query = "SELECT post_gallery_img FROM posts WHERE post_id = $get_post_id";
$select_gallery_imgs = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($select_gallery_imgs)) {
$post_gallery_img = $row['post_gallery_img'];
$post_gallery_img = explode(',', $row['post_gallery_img']);
foreach($post_gallery_img as $out) {
echo '<img id="editPostGalleryImgs" src="../userImages/' . $out . '" alt="Post Image">';
}
}
现在我的目标是让用户单击第二个图像并将其从数组中删除,当单击“更新帖子”时,post_gallery_img 列将更新为新数组。
我有一个类似这样的更新查询。
$implodeArray = implode(',', array_filter($post_gallery_img));
$query = "UPDATE posts SET post_gallery_img = CONCAT('{$implodeArray}' , ',') WHERE post_id = $get_post_id ";
$delete_img = mysqli_query($connection, $query);
【问题讨论】:
标签: php mysql sql arrays mysqli