include 'connection.php';
$count_sql = 'select count(id) as c from user';
$result = mysqli_query($conn, $count_sql);
$data = mysqli_fetch_assoc($result);
//得到总的用户数
$count = $data['c'];
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
/*
if (isset($_GET['page'])) {
$page = (int) $_GET['page'];
} else {
$page = 1;
}
*/
//每页显示数
$num = 5;
//得到总页数
$total = ceil($count / $num);
if ($page <= 1) {
$page = 1;
}
if ($page >= $total) {
$page = $total;
}
$offset = ($page - 1) * $num;
$sql = "select id,username,createtime,createip from user order by id desc limit $offset , $num";
$result = mysqli_query($conn, $sql);
if ($result && mysqli_num_rows($result)) {
//存在数据则循环将数据显示出来
echo '<table width="800" border="1">';
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
echo '<td>' . $row['username'] . '</td>';
echo '<td>' . date('Y-m-d H:i:s', $row['createtime']) . '</td>';
echo '<td>' . long2ip($row['createip']) . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">编辑用户</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">删除用户</a></td>';
echo '</tr>';
}
echo '<tr><td colspan="5"><a href="page.php?page=1">Homepage</a> <a href="page.php ?page=' . ($page - 1) . '">Previous page</a> <a href="page.php?page=' . ($page 1) . '">Next Page</a> <a href="page.php?page=' . $total . '">Last page</a> The current page is ' . $page . 'Page total' . $total . 'Page</td></tr>';
心境2018-07-26 15:37:44
echo '<tr><td colspan="5"><a href="page_divide.php?page=1">Homepage</a>
<a href="page_divide.php?page=' . ($page==1?1:$page-1). '">Previous page</a>
<a href=" page_divide.php?page=' . ($page ==$total?$total:$page+1) . '">Next page</a>
<a href="page_divide .php?page=' . $total . '">Last page</a>
The current page is ' . $page . 'Page total' . $total . 'Page</td> </tr>';