html代碼javascript
<!doctype html>
<html >
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script type="text/javascript" src="js/jquery.js"></script>
<title>Document</title>
</head>
<style type="text/css">
table.imagetable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
table.imagetable th {
background:#b5cfd2 url('cell-blue.jpg');
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}
table.imagetable td {
background:#dcddc0 url('cell-grey.jpg');
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}
</style>
<body>
<table class="imagetable">
<tr>
<th>id</th>
<th>姓名</th>
<th>密碼</th>
<th>性別</th>
<th>系部</th>
<th>班級</th>
<th>電話</th>
<th>操做</th> <!-- 添加一個操做列-->
</tr>
<?php
header( 'Content-Type:text/html;charset=utf-8 ');
include_once("conn/conn.php"); //引入導入數據庫控制頁面
$sql="SELECT*from user"; //查詢數據庫中的user;
$r=mysqli_query($link,$sql);
$row=mysqli_fetch_array($r); //查詢出來的數組類型
while ($row=mysqli_fetch_array($r)){
/*print_r($row);
echo "<br>";*/
/* echo $row["name"]."=>".$row["mima"]; //查詢姓名和密碼 也能夠用鍵來查詢
echo "<br>";*/
?>
<tr>
<td><?php echo $row["id"]?></td>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["mima"]?></td>
<td><?php echo $row["xingbie"]?></td> <!-- 從數據庫中查詢出的數據裝着表格中-->
<td><?php echo $row["xibu"]?></td>
<td><?php echo $row["banji"]?></td>
<td><?php echo $row["tex"]?></td>
<td style="color: red;"><a href="" onclick="del( <?php echo $row["id"]?> );">刪除</a></td> <!-- 在列中添加刪除onclick實現跳轉-->
</tr>
<?php
}
?>
<script>
function del($id) {
var id=$id;
if (id){
$.get("shanchu.php",{id:id},function (data) { /*get獲取數據*/
if (data=201){
alert("成功");
window.location.href=window.location.href; /* 刷新*/
}else {
alert("失敗");
}
});
}else {
alert("失敗");
}
}
</script>
</table>
</body>
</html>
php代碼
<?phpheader( 'Content-Type:text/html;charset=utf-8 ');include_once("conn/conn.php");$id=$_GET["id"];$sql="delete from USER WHERE id=$id";$r=mysqli_query($link,$sql);if ($r){ echo "201";}else{ echo "200";}