首页 > 开发 > PHP > 正文

php mysql数据批量删除实现代码

2024-05-04 21:59:01
字体:
来源:转载
供稿:网友

我们一般是获取表单提交的数据,如果下面我们利用checkbox[]来操作,下面看实例:

  1. "form1" name="form1" method="post" action=""
  2.   1 
  3.   "checkbox" name="checkbox[]" id="checkbox" value="1" /> 
  4.   2 
  5.   "checkbox" name="checkbox[]" id="checkbox2" value="2"  /> 
  6.   3 
  7.   "checkbox" name="checkbox[]" id="checkbox3" value="3" /> 
  8.    
  9.   "submit" name="button" id="button" value="提交" /> 
  10. //开源:Vevb.com 
  11.  
  12. if$_post ) 
  13.  print_r( $_post );  
  14.  //输也是以数据形式保存的, 
  15.  /* 
  16.  array 
  17.  ( 
  18.   [checkbox] => array 
  19.    ( 
  20.     [0] => 1 
  21.     [1] => 2 
  22.     [2] => 3 
  23.    ) 
  24.  
  25.   [button] => 提交 
  26.  ) 
  27.  
  28.  //这样就好操作了,我们只要如下 
  29.  */ 
  30.  $array = $_post['checkbox']; 
  31.  print_r( $array ); 
  32.  /* 
  33.  //得到内容如下: 
  34.  array 
  35.  ( 
  36.   [0] => 1 
  37.   [1] => 2 
  38.   [2] => 3 
  39.  ) 
  40.  

其实1,2,3就是我们想要的内容,我们就可以利用sql的in来批量实现删除了.

  1. $ids = implode(',',$array ); 
  2. $sql ="delete from 表名 where id in($ids ) "
  3. mysql_query($sql); 

这样就实现的数据的批量删除.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表