<?php
$con
= mysqli_connect('localhost','root','123456','test');
mysqli_set_charset(
$con
,'utf8');
if
(!
$con
){
die
('Could not connect:' . mysql_error(
$con
));
}
$sql
= "select * from login";
$result
= mysqli_query(
$con
,
$sql
);
$rows
=
array
();
while
(
$row
= mysqli_fetch_assoc(
$result
)){
$rows
[] =
$row
;
}
?>
<!DOCTYPE html PUBLIC "-
<html xmlns="http:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{padding:0;margin:0;}
.pd-lr{padding: 5px 20px}
</style>
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td width="30">
全选:<input id="checkAll" type="checkbox">
</td>
<td width="30">id</td>
<td width="30">用户名</td>
<td width="30">密码</td>
<td width="30">邮箱</td>
<td width="40">操作</td>
<td width="30">提交时间</td>
</tr>
</thead>
<tbody>
<?php
foreach
(
$rows
as
$k
=>
$v
) {
?>
<tr>
<td><input type="checkbox" name="box" value="<?=
$v
['id'] ?>"
class
="checkOne"></td>
<td><?php
echo
$v
['id'];?></td>
<td><?php
echo
$v
['username'];?></td>
<td><?php
echo
$v
['password'];?></td>
<td><?php
echo
$v
['email'];?></td>
<td>
<a href="javascript:confirm_delete('shanchu.php?sno=<?php
echo
$v
['id'];?>')">删除</a>
<a href='xiugai.php?sno=<?php
echo
$v
['id'];?>'>修改</a>
</td>
<td><?php
echo
$v
['CreateTime'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<p
class
="pd-lr">
<button style="float:left;">批量删除</button>
<!-- 数据表的总条数 -->
<p style="float:right;display:inline-block;">总共<span><?php
$sql2
= "SELECT
COUNT
(*) FROM login";
$all_value
=
$con
->query(
$sql2
);
while
(
$nums
=
$all_value
->fetch_assoc()) {
echo
(
$nums
['
COUNT
(*)']);
} ?></span>条</p>
</p>
<script src="./jquery-3.2.1.min.js"></script>
<script>
function
confirm_delete(url){
if
(confirm('您确定要执行删除操作?')){
window.location.href=url;
}
else
{
return
false;
}
}
$("#checkAll").on('change',
function
() {
if
($(this).is(":checked")) {
$(".checkOne").prop("checked",true);
}
else
{
$(".checkOne").prop("checked",false);
}
});
$('button').click(
function
(){
var
ids=$('.checkOne:checkbox');
var
str='';
var
count
=0;
for
(
var
i=0;i<ids.length;i++){
if
(ids.eq(i).is(':checked')){
str+=','+ids.eq(i).val();
count
++;
}
}
var
str=str.
substr
(1);
if
(confirm('你确定要删除这'+
count
+'条数据吗?')){
$.ajax({
type:'GET',
url:'adminDel.php',
data:{'str':str},
success:
function
(res){
if
(res>0){
for
(
var
i=ids.length-1;i>=0;i--){
if
(ids.eq(i).is(':checked')){
ids.eq(i).parent().parent().remove();
}
}
}
alert('删除成功!');
window.location.reload();
},
error:
function
(data){
console.log("数据加载失败",data);
}
})
}
return
false;
});
</script>
</body>
</html>