
關鍵代碼在tr、button和script那裡
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>資料表管理頁面</title>
<style>
.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #ebab3a;border-collapse: collapse;table-layout: fixed;}
.tftable th {font-size:12px;background-color:#e6983b;border-width: 1px;padding: 8px;border-style: solid;border-color: #ebab3a;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #ebab3a;}
.tftable tr:hover {background-color:#ffff99;}
</style>
</head>
<body>
<h1 style="text-align: center">學生資訊表</h1>
<table class="tftable">
<tr>
<th>學号</th>
<th>姓名</th>
<th>性别</th>
<th>專業</th>
<th>班級</th>
<th>操作</th>
</tr>
<?php
$dbms='mysql'; //資料庫類型
$host='localhost'; //資料庫主機名
$dbName='classmanager'; //使用的資料庫
$user='root'; //資料庫連接配接使用者名
$pass=''; //對應的密碼
$dsn="$dbms:host=$host;dbname=$dbName";
$num=0;
$conn = new PDO($dsn, $user, $pass); //初始化一個PDO對象
//echo("連接配接成功\n");
$conn->query("set names utf8");
foreach ($conn->query('SELECT * from student') as $row) {
$rowidd = 'stu'.$num;
echo("<tr id=".$rowidd."><td>"
.$row[0]."</td><td>"
.$row[1]."</td><td>"
.$row[2]."</td><td>"
.$row[3]."</td><td >"
.$row[4]."</td><td >"
."<button onClick='stuVisible();'>添加</button>"
."<button onClick='edit($rowidd);'>編輯</button>"
."<button>删除</button>"
."</td></tr>");
$num++;
}
?>
</table>
<div id="sf"; style="margin-left: 40%; display:none;">
<form name="studentForm" action="s_insert.php" onsubmit="return check()" method="post">
學号: <input type="text" name="sno" value="123456"><br />
姓名: <input type="text" name="sname" value="123456"><br />
性别: <input type="text" name="sgender" value="123456"><br />
專業: <input type="text" name="major" value="123456"><br />
學院: <input type="text" name="classno" value="123456"><br />
<input type="submit" value="添加">
</form>
</div>
<script>
function stuVisible(){
document.getElementById('sf').style.display='block';
}
function edit(rid){
alert(rid.cells[0].innerHTML);
}
</script>
</body>
</html>