//查询共有多少行数据
$sql1 = "select count(*) from user";
$ret1 = mysql_query($sql1);
$row1 = mysql_fetch_row($ret1);
$tot = $row1[0];
//每页多少行数据
$length = 5;
//总页数
$totpage = ceil($tot / $length);
//当前页数
$page = @$_GET['p'] ? $_GET['p'] : 1;
//limit 下限
$offset = ($page - 1) * $length;
echo "
ID | ";USER | ";PASS | ";
---|---|---|
{$row2['id']} | {$row2['name']} | {$row2['pass']} | ";
//上一页和下一页
$prevpage = $page - 1;
if ($page >= $totpage) {
$nextpage = $totpage;
} else {
$nextpage = $page 1;
}
//跳转
echo "
核心点:
<1>“$sql2 = "select * from user order by id limit {$offset}, {$length}";”,$offset、$length和页数之间的关系。
<2>上一页和下一页的获得方式,以及临界点。