首页 > 开发 > 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. { 
  14.  print_r( $_post );  
  15.  //输也是以数据形式保存的, 
  16.  /* 
  17.  array 
  18.  ( 
  19.   [checkbox] => array 
  20.    ( 
  21.     [0] => 1 
  22.     [1] => 2 
  23.     [2] => 3 
  24.    ) 
  25.  
  26.   [button] => 提交 
  27.  ) 
  28.  
  29.  //这样就好操作了,我们只要如下 
  30.  */ 
  31.  $array = $_post['checkbox']; 
  32.  print_r( $array ); 
  33.  /* 
  34.  //得到内容如下: 
  35.  array 
  36.  ( 
  37.   [0] => 1 
  38.   [1] => 2 
  39.   [2] => 3 
  40.  ) 
  41.  
  42. } 

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

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

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

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