如何使用php jquery进行多次删除

时间:2016-03-03 18:03:29

标签: php

这里我有一个表,其数据来自数据库(Mysql DBMS)Table

在此表中,我可以逐个删除一本书,但我需要的是一次删除多本书 像这样enter image description here

但实际上我不知道如何做到这一点你们可以帮我一个忙吗?我会感恩的

1 个答案:

答案 0 :(得分:1)

使用[]表示法创建一个具有相同名称的复选框列表,但大概是不同的值,记录ID:

<input type="checkbox" name="record_id[]" value="42" />
<input type="checkbox" name="record_id[]" value="43" />
<input type="checkbox" name="record_id[]" value="44" />
<input type="checkbox" name="record_id[]" value="45" />

选择其中一些后,它们将作为$_POST['record_id']数组传递给服务器。

执行foreach

foreach ($_POST['record_id'] as $id) {
     // delete record with $id here
}

或implode'em,例如:

$sql = "DELETE FROM `mytable` WHERE id IN (" . implode(', ', $_POST['record_id']) . ")";