php批量删除数据的操作方法
2018-03-10 20:32:39
•
阅读
打赏
这篇文章主要为大家详细介绍了php批量删除数据的操作方法,批量删除页面和处理界面,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
批量删除html页面 list.php
<html>
<body>
<form action="del.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.class.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.class.php
class DBDA
{
public $host = "localhost";
public $uid = "root";
public $pwd = "123456";
public $dbname = "user";
/**
* 执行SQL语句返回相应的结果
* @param $sql string 要执行的SQL语句
* @param $type integer 代表SQL语句的类型,0代表增删改,1代表查询
* @return boolean
*/
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;
}
}
}
删除处理界面 del.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}')";
if ($db->query($sql, 0)) {
header("location:piliangcaozuo.php");
}
以上就是本文php批量删除数据的操作方法的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。
相关推荐
深度学习 -- 损失函数
深度残差网络(Deep Residual Networks (ResNets))
深度学习 -- 激活函数
神经网络训练 -- 调整学习速率
生成对抗网络(GAN)改进与发展
生成对抗网络(GAN)优点与缺点
生成对抗网络(GAN)的训练
生成对抗网络(GAN)基本原理
生成模型与判别模型