前台
<form action="test.PHP" method="post">
<table border="1">
<tr>
<?php show() ?>
<tr><td colspan="3"><input type="submit" value="批量删除"></td></tr>
</table>
<?PHP
//显示列表
function show()
{
//连接数据库
@MysqL_connect('localhost','root','');
MysqL_select_db('test');
MysqL_query('set names utf8');
$sql = "select id,name from test";
$res = MysqL_query($sql);
//循环取出数据
while($row = MysqL_fetch_row($res))
{
echo "<tr>
<td>
后台
//接收post传来的数组
$arr = $_POST["item"];
/**
-
批量删除
-
@param $arr <array()>
-
@return $res 成功or失败
*/
function batch_del($arr)
{
@MysqL_connect('localhost','');
MysqL_select_db('test');
MysqL_query('set names utf8');//把数组元素组合为字符串:
$str = implode("','",$arr);
//in 表示多个
$sql = "delete from test where id in('{$str}')";
$res = MysqL_query($sql);if (!$res){
echo "删除失败";
}else {if (<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>_affected_rows()>0){ echo "<a href="https://www.jb51.cc/tag/shanchu/" target="_blank" class="keywords">删除</a>成功"; }else { echo "没有行受到影响"; }
}
}
batch_del($arr);