简体   繁体   English

删除选定的图像(复选框/ PHP / MySQL)

[英]Delete Selected Images (Checkbox/PHP/MySQL)

I have images displayed from Database as follows: 我有从数据库显示的图像,如下所示:

<li>
    <input type="checkbox" id="1" />
    <a rel="gallery_group" href="images/big/1.jpg" title="Image 1">
        <img src="images/small/1.jpg" alt="" />
    </a>
</li>
<li>
    <input type="checkbox" id="2" />
    <a rel="gallery_group" href="images/big/2.jpg" title="Image 2">
        <img src="images/small/2.jpg" alt="" />
    </a>
</li>

So as you see each image has its unique ID (Its all extracted from the Database which has the ID of the images that exist: 1, 2, 3, 4, 5 etc...) 因此,如您所见,每个图像都有其唯一的ID (所有图像均从数据库中提取,该数据库具有已存在的图像的ID:1、2、3、4、5等...)

What i want is that, when someone for example selected Image 1, 2, 4 (checkbox ID: 1, 2, 4) and click submit, it will be send to a function that deletes those images from the database. 我想要的是,当某人例如选择图像1、2、4 (复选框ID:1、2、4)并单击“提交”时,它将被发送到从数据库中删除那些图像的功能。

  • How can i check on submit which checkbox have been selected? 如何检查提交已选中的复选框?
  • How can i send them to the function that delete them from the database? 我如何将它们发送到从数据库中删除它们的功能?

You have to set the name and value of the checkbox in order to check if it was checked or not. 您必须设置复选框的名称和值,以检查是否已选中。 For example, change your html to this: 例如,将您的html更改为此:

<li>
  <input type="checkbox" id="2" name="delete_images[]" value="2.jpg" />
  <a rel="gallery_group" href="images/big/2.jpg" title="Image 2">
    <img src="images/small/2.jpg" alt="" />
  </a>
</li>

delete_images[] will be an array of all of the images that you want to delete. delete_images []将是您要删除的所有图像的数组。 It will only contain the values of the checked check-boxes. 它仅包含选中的复选框的值。

In your function, get all of the images like this: $images = isset($_REQUEST["delete_images"]) ? $_REQUEST["delete_images"] : null; 在您的函数中,像这样获得所有图像: $images = isset($_REQUEST["delete_images"]) ? $_REQUEST["delete_images"] : null; $images = isset($_REQUEST["delete_images"]) ? $_REQUEST["delete_images"] : null;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM