How to implement select-all deletion in php: first set the select-all "checkbox"; then name the class ckb, and cleverly put the id value into the input; then process the id and remove the first one comma; finally operate the database in the background and handle the deletion action.
Recommended: "PHP Tutorial"
jQuery php simple method to select all and delete
Share it with everyone for your reference, the details are as follows:
删除
↑Select all checkbox
↑To delete items, the same named class is ckb, which is convenient for operation. Cleverly put the id value into the input for easy access.
function selectAll() { if ($('#ckb_selectAll').is(':checked')) { $(".ckb").attr("checked", true); //全部选中 } else { $(".ckb").attr("checked", false);//全部取消 } }
↑Selected event
function del_() { var ids = ''; $(".ckb").each(function() { if ($(this).is(':checked')) { ids += ',' + $(this).val(); //逐个获取id } }); ids = ids.substring(1); // 对id进行处理,去除第一个逗号 if (ids.length == 0) { alert('请选择要删除的选项'); } else { if (confirm("确定删除?删除后将无法恢复。")) { url = "action=del_call_record&ids=" + ids; $.ajax({ type: "post", url: "send.php", data: url, success: function(json) { if (parseInt(json.counts) > 0) { alert(json.des); location.reload(); } else { alert(json.des); } }, error: function(XMLHttpRequest, textStatus) { alert("页面请求错误,请检查重试或联系管理员!\n" + textStatus); } }); } } }
↑Deletion is handled with ajax.
↓Operate the database in the background and process deletion actions.
$ids = trim($_REQUEST['ids']); $del_sql = "DELETE FROM vicidial_call_record WHERE id IN(".$ids.")"; //print_r($del_sql);exit; if (mysqli_query($db_conn, $del_sql)) { $counts = "1"; $des = "成功"; } else { $counts = "0"; $des = "失败"; } $json_data = "{"; $json_data. = "\"counts\":".json_encode($counts).","; $json_data. = "\"des\":".json_encode($des).""; $json_data. = "}"; echo $json_data; break;
The above is the detailed content of How to implement the function of selecting all and deleting in php. For more information, please follow other related articles on the PHP Chinese website!