首页 > 数据库技术 > 详细

MYSQLi数据访问批量删除

时间:2018-01-16 13:26:27      阅读:221      评论:0      收藏:0      [点我收藏+]
<link href="../bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="../bootstrap.min.js"></script>
<script src="../jquery-1.11.2.min.js"></script>
<body>
<form action="./pldelete.php" method="post">
<table class="table table-striped">
  <caption>人员信息展示</caption>
  <thead>
    <tr>
      <th><input type="checkbox" id="ckall"/>代号</th>
      <th>姓名</th>
      <th>性别</th>
      <th>民族</th>
      <th>生日</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
  	<?php
	$db = new MySQLi("localhost","root","123456","crud");
	$sql = "select info.code,info.name,sex,nation.name,birthday from info,nation where info.nation=nation.code";
	$result = $db->query($sql);
	if($result){
		$arr = $result->fetch_all();
		foreach($arr as $v){
			$sex = $v[2]?"男":"女";
			echo "<tr>
      <td><input class=‘ck‘ type=‘checkbox‘ name=‘ck[]‘ value=‘{$v[0]}‘ />{$v[0]}</td>
      <td>{$v[1]}</td>
      <td>{$sex}</td>
      <td>{$v[3]}</td>
      <td>{$v[4]}</td>
	  <td><a href=‘./delete.php?code={$v[0]}‘ onclick=\"return confirm(‘确认删除么?‘)\"><button type=‘button‘ class=‘btn btn-primary btn-sm‘>删除</button></a></td>
    </tr>";
		}
	}
	?>
  </tbody>
</table>

<div><input type="submit" value="批量删除" /></div>
</form>
<script type="text/javascript">
var ckall = document.getElementById("ckall");
ckall.onclick = function(){
	var xz = ckall.checked;
	var ck = document.getElementsByClassName("ck");
	for(var i=0;i<ck.length;i++){
		ck[i].checked = xz; 
	}
}
</script>
</body>

 技术分享图片

删除页面

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

//delete from info where code in(‘p001‘,‘p002‘,‘p003‘)

$str = implode("‘,‘",$arr);
$sql = "delete from info where code in(‘{$str}‘)";

$db = new MySQLi("localhost","root","123456","crud");
$result = $db->query($sql);
if($result){
	header("location:main.php");
}else{
	echo "删除失败!";
}

 技术分享图片

 

MYSQLi数据访问批量删除

原文:https://www.cnblogs.com/navyouth/p/8295764.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!