98 lines
2.4 KiB
PHP
98 lines
2.4 KiB
PHP
<?php
|
|
require_once "db_config.php"; // 引入数据库配置文件
|
|
$conn = $link;
|
|
// 每页显示的记录数
|
|
$limit = 10;
|
|
|
|
// 获取当前的action和offset参数
|
|
$action = isset($_GET['action']) ? $_GET['action'] : 'top';
|
|
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
|
|
|
|
// 获取总记录数
|
|
$sql_count = "SELECT COUNT(*) AS total FROM user_70";
|
|
$result_count = $conn->query($sql_count);
|
|
$total_records = $result_count->fetch_assoc()['total'];
|
|
|
|
// 计算总页数
|
|
$total_pages = ceil($total_records / $limit);
|
|
|
|
// 根据action计算新的offset
|
|
switch ($action) {
|
|
case 'top':
|
|
$offset = 0;
|
|
break;
|
|
case 'previous':
|
|
$offset = max(0, $offset - $limit);
|
|
break;
|
|
case 'next':
|
|
$offset = min($total_records - $limit, $offset + $limit);
|
|
break;
|
|
case 'bottom':
|
|
$offset = max(0, ($total_pages - 1) * $limit);
|
|
break;
|
|
default:
|
|
$offset = 0;
|
|
break;
|
|
}
|
|
|
|
// 查询当前页的数据
|
|
$sql = "SELECT name FROM user_70 LIMIT $offset, $limit";
|
|
$result = $conn->query($sql);
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>姓名列表</title>
|
|
<style>
|
|
table {
|
|
width: 300px;
|
|
border-collapse: collapse;
|
|
margin: 20px auto;
|
|
}
|
|
th, td {
|
|
border: 1px solid #000;
|
|
text-align: center;
|
|
padding: 8px;
|
|
}
|
|
a {
|
|
margin: 0 5px;
|
|
text-decoration: none;
|
|
color: blue;
|
|
}
|
|
a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table>
|
|
<tr>
|
|
<th>姓名列表</th>
|
|
</tr>
|
|
<?php
|
|
// 输出数据
|
|
if ($result->num_rows > 0) {
|
|
$index = $offset + 1; // 起始序号
|
|
while ($row = $result->fetch_assoc()) {
|
|
echo "<tr><td>{$index}. {$row['name']}</td></tr>";
|
|
$index++;
|
|
}
|
|
} else {
|
|
echo "<tr><td>没有数据</td></tr>";
|
|
}
|
|
?>
|
|
<tr>
|
|
<td>
|
|
<a href="list_72.php?action=top&offset=0">首页</a>
|
|
<a href="list_72.php?action=previous&offset=<?php echo $offset; ?>">上一页</a>
|
|
<a href="list_72.php?action=next&offset=<?php echo $offset; ?>">下一页</a>
|
|
<a href="list_72.php?action=bottom&offset=<?php echo ($total_pages - 1) * $limit; ?>">末页</a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</body>
|
|
</html>
|