首页 > php与数据库 > php mysql数据批量删除实现代码

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

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

<form id="form1" name="form1" method="post" action="">
  1
  <input type="checkbox" name="checkbox[]" id="checkbox" value="1" />
  2
  <input type="checkbox" name="checkbox[]" id="checkbox2" value="2"  />
  3
  <input type="checkbox" name="checkbox[]" id="checkbox3" value="3" />
  
  <input type="submit" name="button" id="button" value="提交" />
</form>

<?
if( $_post )
{
 print_r( $_post ); 
 //输也是以数据形式保存的,
 /*
 array
 (
  [checkbox] => array
   (
    [0] => 1
    [1] => 2
    [2] => 3
   )
 
  [button] => 提交
 )
 
 这样就好操作了,我们只要如下
 */
 $array = $_post['checkbox'];
 print_r( $array );
 /*
 得到内容如下
 
 array
 (
  [0] => 1
  [1] => 2
  [2] => 3
 )

 其实1,2,3就是我们想要的内容,我们就可以利用sql的in来批量实现删除了。
*/
 $ids = implode(',',$array );
 $sql ="delete from 表名 where id in($ids ) ";
 mysql教程_query($sql);
 
 //这样就实现的数据的批量删除哦。
 //本站原创转载注明来源http://www.phprm.com 否则必究!
}

永久地址:http://www.phprm.com/database/37393.html

转载随意~请带上教程地址吧^^

标签:none

发表留言