php批量删除操作 php批量删除操作(数据访问)

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

php批量删除操作 php批量删除操作(数据访问)

ChrissZhao   2021-03-24 我要评论
想了解php批量删除操作(数据访问)的相关内容吗,ChrissZhao在本文为您仔细讲解php批量删除操作的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php批量删除操作,php批量删除,php删除处理,下面大家一起来学习吧。

1.批量删除页面 piliangcaozuo.php

<body>
<form action="shanchu.php" method="post">
<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td><input type="checkbox" name="qx" onclick="quanxuan(this)"/>代号</td>
    <td>名称</td>   
  </tr>
  <?php
   require"DBDA.class1.php";
   $db = new DBDA();
   $sql = "select * from nation";
   $arr = $db->query($sql);
   foreach($arr as $v)
  {
    echo "<tr>
        <td><input type='checkbox' name='ck[]' class='ck' value='{$v[0]}'/>{$v[0]}</td>
        <td>{$v[1]}</td>   
       </tr>";
  }
  ?>  
</table>
<input type="submit" value="批量删除" />
</form>
</body>
<script type="text/javascript">
function quanxuan(qx)
{
  var ck=document.getElementsByClassName("ck");
  if(qx.checked)
  {
    for(var i=0;i<ck.length;i++)
    {
      ck[i].setAttribute("checked","checked");
    }
  }
  else
  {
    for(var i=0;i<ck.length;i++)
    {
      ck[i].removeAttribute("checked");
    }
  }
}
</script>
</html>

引用的封装类 DBDA.class1.php

<?php
class DBDA
{
  public $host = "localhost";
  public $uid = "root";
  public $pwd = "123";
  public $dbname = "test_123";
  //执行SQL语句返回相应的结果
  //$sql 要执行的SQL语句
  //$type 代表SQL语句的类型,0代表增删改,1代表查询
  function query($sql,$type=1)
  {
    $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
    
    $result = $db->query($sql);
    
    if($type)
    {
      //如果是查询,显示数据
      return $result->fetch_all();
    }
    else
    {
      //如果是增删改,返回true或者false
      return $result;
    }
  }
}

2.删除处理界面 sanchu.php

<?php
$arr = $_POST["ck"];

require"DBDA.class.php";
$db = new DBDA();
//delete from nation where code in('n001','n002','n003')

$str = implode("','",$arr); 
$sql = "delete from nation where code in('{$str}')";
/*echo $sql;*/
if($db->query($sql,0))
{
  header("location:piliangcaozuo.php");
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们