<?php require_once('connect.php'); $sel_query="select * from demotb"; mysql_query("set names utf8"); $sel_results=mysql_query($sel_query); /** * 分页信息设置 * * 1 设置当前页为$apage * 2 设置每页显示页数为$pagesize * 3 设置总共数量为$totalrows * 4 设置最大页数为$maxpage */ $page= isset($_GET['page']) ? $_GET['page'] : 1; $pagesize=4; $totalrows; $totalpage; $maxpage; $res=mysql_query("select count(*) from demotb"); $rs=mysql_fetch_array($res); $totalrows=$rs[0]; // echo $totalrows; $totalpage=ceil($totalrows/$pagesize); // echo $totalpage; // if ($page>$totalpage) { $page=$totalpage; } if ($page<1) { $page=1; } $limit=' limit '.($page-1)*$pagesize.','.$pagesize; ?> <table> <tr><th>Name:</th><th>Age:</th></tr> <?php mysql_query('set names utf8'); $list_query="select * from demotb {$limit}"; $results=mysql_query($list_query); while ($rows=mysql_fetch_assoc($results)) { echo '<tr><td>'.$rows['name'].'</td><td>'.$rows['age'].'</td></tr>'; } echo '<tr><td>当前页 :'.$page.'</td><td><a href=list.php?page=1>首页</a></td><td><a href=list.php?page='.($page-1).'>上一页</a></td><td><a href=list.php?page='.($page+1).'>下一页</a></td><td><a href=list.php?page='.($totalpage).'>末页</a></td></tr>'; ?> </table>