<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function doDel(id) {
if (confirm("确定要删除么?")) {
window.location = 'act.php?action=del&id=' + id;
}
}
</script>
</head>
<style>
th, td {
width: 100%;
word-break: keep-all; /* 不换行 */
white-space: nowrap; /* 不换行 */
overflow: hidden; /* 内容超出宽度时隐藏超出部分的内容 */
text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/
}
</style>
<body>
<center>
<table width="600" border="1">
<tr style="background: #666666;font-size: 30px ;text-align: center">
<td colspan="6">学生个人信息表</td>
</tr>
<tr>
<th>姓名</th>
<th>性别</th>
<th>爱好</th>
<th>家庭住址</th>
<th>备注</th>
</tr>
<?php
//1.连接数据库
try {
$pdo = new PDO("mysql:host=localhost;dbname=test;", "root", "251233");
} catch (PDOException $e) {
die("数据库连接失败" . $e->getMessage());
}
//2.解决中文乱码问题
$pdo->query("SET NAMES 'UTF8'");
//3.执行sql语句,并实现解析和遍历
$sql = "SELECT * FROM info ";
foreach ($pdo->query($sql) as $row) {
echo "<tr>";
echo "<td>{$row['name']}</td>";
echo "<td>{$row['sex']}</td>";
echo "<td>{$row['hobby']}</td>";
echo "<td>{$row['address']}</td>";
echo "<td>{$row['remark']}</td>";
echo "<td>
<a href='javascript:doDel({$row['id']})'>删除</a>
<a href='ex01c.php?id=({$row['id']})'>修改</a>
</td>";
echo "</tr>";
}
?>
</table>
</center>
</body>
</html>