2017.5.4

批量删除

<h1>民族信息</h1>
<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.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>

 

 

操作界面代码

<?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:piliangshanchu.php");
}

posted @ 2017-05-04 14:41  雪花飘刂  阅读(132)  评论(0编辑  收藏  举报