QQ咨询 官方微信

添加微信好友

官方小程序

百度小程序

微信小程序

头条小程序

关于我们

PHP基础

PHP 批量操作删除,同时支持单条删除和多条

 admin  2016-03-14 18:40:35
PHP  执行部分:

  1. <?php   
  2. include('checkadmin.php');   
  3. header('Content-Type: text/html; charset=utf-8');   
  4. if($_POST['btnSave']){   
  5.        
  6.     if(emptyempty($_POST['id'])){   
  7.             echo"<script>alert('必须选择一个产品,才可以删除!');history.back(-1);</script>";   
  8.             exit;   
  9.         }else{   
  10.         /*如果要获取全部数值则使用下面代码*/   
  11.            
  12.         $id= implode(",",$_POST['id']);   
  13.         $str="DELETE FROM `product` where id in ($id)";   
  14.         mysql_query($str);   
  15.         echo "<script>alert('删除成功!');window.location.href='product_list.php';</script>";   
  16.     }   
  17. }   
  18. ?>   

HTML 页面部分:

  1. <form id="form2" name="form2" method="post" action="del_product.php">   
  2.     <label>   
  3.         <input type="checkbox" name="id[]" value="1" style="background:none; border:none;" />   
  4.             1   
  5.     </label>   
  6.     <label>   
  7.         <input type="checkbox" name="id[]" value="2" style="background:none; border:none;" />   
  8.             2   
  9.     </label>   
  10.     <label>   
  11.         <input type="checkbox" name="id[]" value="3" style="background:none; border:none;" />   
  12.             3   
  13.     </label>   
  14.     <label>   
  15.         <input type="checkbox" name="id[]" value="4" style="background:none; border:none;" />   
  16.             4   
  17.     </label>   
  18.     <label>   
  19.         <input type="checkbox" name="id[]" value="5" style="background:none; border:none;" />   
  20.             5   
  21.     </label>   
  22.     <div style="padding-left:20px;">   
  23.         <input type="button" value="全选" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onClick="selectBox('all')"/>   
  24.         <input type="button" value="反选" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" onClick="selectBox('reverse')"/>   
  25.         <input type="submit" name="btnSave" style="background:url(images/cheall.jpg) no-repeat; width:60px; height:23px; border:none;" value="删除"/>   
  26.     </div>   
  27. </form>   


JS判断部分:

 

  1. <script type="text/javascript" language="javascript">   
  2.   function selectBox(selectType){   
  3.   var checkboxis = document.getElementsByName("id[]");   
  4.   if(selectType == "reverse"){   
  5.       for (var i=0; i<checkboxis.length; i++){   
  6.           //alert(checkboxis[i].checked);   
  7.           checkboxis[i].checked = !checkboxis[i].checked;   
  8.       }   
  9.   }   
  10.   else if(selectType == "all")   
  11.   {   
  12.       for (var i=0; i<checkboxis.length; i++){   
  13.           //alert(checkboxis[i].checked);   
  14.           checkboxis[i].checked = true;   
  15.       }   
  16.   }   
  17. }   
  18. </script>   

 

¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

本文《PHP 批量操作删除,同时支持单条删除和多条》发布于石头博客文章,作者:admin,如若转载,请注明出处:https://www.pweb123.com/html/php/626.html,否则禁止转载,谢谢配合!

文章点评

我来说两句 已有0条评论
点击图片更换

添加微信好友

添加微信好友

微信小程序

百度小程序