<html> <head> <title>显示所有用户</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> </head> <body> <a href="Regeister.php">注册用户</a> <table border="1px" cellpadding="0px" cellspacing="0px"> <tr> <td>用户编号</td> <td>用户姓名</td> <td>用户手机号</td> <td>用户邮箱</td> <td>用户状态</td> <td>登录时间</td> <td>操作</td> </tr> <?php date_default_timezone_set('Asia/Shanghai'); $conn = mysql_connect("localhost","root","123456"); mysql_select_db("dbwpw"); mysql_query('set names utf8'); //判断page变量是否存在 存在则获取值 不存在则赋值1 $page = isset($_GET["page"]) ? intval($_GET["page"]):1; $pagesize = 3; //每页显示的数据行数 //查询数据的总数total $total=mysql_fetch_assoc(mysql_query("SELECT count(*) as total from users ")); //根据键值获取总数 $num=$total["total"]; //获得总页数 pagenum $pagenum=ceil($num/$pagesize); //先判断page的值 //如果page值大于总页数 If($page>$pagenum){ $page=$pagenum; } //如果page值小于1 if($page<1){ $page=1; } //判断每页显示 $offset = ($page - 1) * $pagesize; $sql = "SELECT userid,username,mobile,email,status,addtime from users order by userid asc limit $offset,$pagesize"; $result = mysql_query($sql,$conn); while($rs = mysql_fetch_assoc($result)) { $time = date('Y-m-d H:i:s', $rs['addtime']); echo '<tr> <td>'.$rs["userid"].'</td> <td>'.$rs["username"].'</td> <td>'.$rs["mobile"].'</td> <td>'.$rs["email"].'</td> <td>'.$rs["status"].'</td> <td>'.$time.'</td> <td><a href="Delete.php?action=delete&id='.$rs["userid"].'">删除</a> <a href="Detail.php?action=detail&id='.$rs["userid"].'">详细</a> <a href="update.php?id='.$rs["userid"].'">修改</a> </td> </tr>'; } ?> </table> <a href="Showuser.php">第一页</a> <?php if($page == 1){ $prev = 1; }else{ $prev = $page-1; } ?> <a href="Showuser.php?page=<?php echo $prev; ?>">上一页</a> <?php if($page>=$pagenum){ $next = $pagenum; }else{ $next = $page+1; } ?> <a href="Showuser.php?page=<?php echo $next; ?>">下一页</a> <a href="Showuser.php?page=<?php echo ($pagenum) ?>">最后一页</a> </body> </html>