我将数字 id 列表发布到我的 php 脚本以进行删除
$("#delete").click(function(){
var arr = $(':checkbox:checked').closest('tr').map(function(i, e) {
return +e.id;
}).get();
var checkedArr = arr.join(',');
$.post('delete.php', {thearray: checkedArr }, function(data) {
for(var row_id in data) {
$("#"+data[row_id]).remove();
}
});
});
然后返回我刚刚发布的 ID
$.post('delete.php', {thearray: checkedArr }, function(data) {
for(var row_id in data) {
$("#"+data[row_id]).remove();
}
});
如何运行 for 循环以便删除行?
<?php
$mysqli = new mysqli("localhost", "root", "", "caliban");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$incoming = $_POST['thearray'];
$query="DELETE FROM caliban where id in ($incoming)";
$mysqli->query($query);
echo $incoming;
$mysqli->close();
?>
但是,我无法删除成功的行。