声明:此代码适用于九品源码框架内使用,只是要记录一种思路。主要是为了解决了批量删除时动态获取ID列表与参数加密的矛盾关系。
思路:批量选中的ID用POST提交,而参数和命令保持以加密传递的方式。
<button type="button" class="btn btn-danger btn-icon" onClick="del_piliang()">批量删除所选数据<i class="entypo-cup"></i></button> 循环输出的行ID: <input type="checkbox" id="limit_xz" name="xuanze_fz" value="<?=$rs["id"]?>" /> <script type="text/javascript"> function del_piliang() { var id_list = ''; var ck = document.getElementsByName("xuanze_fz"); //定义checkbox数组变量 for (var i = 0; i < ck.length; i++) { if (ck[i].checked) id_list += ck[i].value + ','; //如果选中,将value添加到变量s中 } if (id_list == '') { alert_go('您没有选择任何内容!', 'alert', '', 'error', '') return false } else { $("#del_pl_list").val(id_list) alert_go('确认批量删除所选的钉钉数据?', 'submit', 'formdel', 'wen', ''); } }</script>
PHP处理删除代码:
if ($action == "del") { $dd_id = $_POST['del_pl_list']; $dd_id = trim($dd_id, ","); $dd_id = "'".str_replace(",", "','", $dd_id)."'"; $sql = "select id,kecheng_name from xy_dingding where bianma_dw='".$vv_bianma_dw."' and banji_id='".$banji_id."' and id in (".$dd_id.") "; $result = $mysqli - >query($sql); while ($rs = $result - >fetch_assoc()) { $kecheng_name = $rs["kecheng_name"]; $sql = "delete from xy_dingding where id='".$rs["id"]."' and bianma_dw='".$vv_bianma_dw."' and banji_id='".$banji_id."' limit 1"; $mysqli - >query($sql); $sql = "delete from xy_dingding_info where kecheng_name='".$kecheng_name."' and bianma_dw='".$vv_bianma_dw."' and banji_id='".$banji_id."' "; $mysqli - >query($sql); $sql = "delete from xy_dingding_keshi where kecheng_name='".$kecheng_name."' and bianma_dw='".$vv_bianma_dw."' and banji_id='".$banji_id."' "; $mysqli - >query($sql); //如果不需要额外的表删除记录可以直接用delete in (ID列表),批量删除 } $back_url = $AES_obj - >aesEn("&page=".$page."&banji_id=".$banji_id."&".$pageurl."&time=".time()); alert_ini(); echo "<script>alert_go('批量删除成功!','alert_go','','ok','?".$back_url."');</script>"; exit; }
以上就是PHP批量删除所选内容的ID与参数加密冲突的解决方法【专用】的详细内容,更多关于PHP批量删除所选内容的ID与参数加密冲突的解决方法【专用】的资料请关注九品源码其它相关文章!