这篇文章主要为大家详细介绍了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免费学习笔记(深入)”;
<?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
装修公司源码,采用DIV+CSS布局,首页顶部采用了超大宽屏banner焦点图切换,带伸缩功能的导航条。首页信息展示量大,有利于SEO优化,首页版块包括,导航,焦点图切换,案例,行业动态,装修经验,装修知识。源码支持伪静态,后台开启即可,服务器必须支持rewrite功能,否则无法实现伪静态功能。信息支持二级分类。后台支持信息批量修改,删除,可以支持,视频,图片,附件上传。
<?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");
}
相关推荐:










