分页吧 关注:10贴子:31
  • 2回复贴,共1

一个分页方法php

只看楼主收藏回复

<?php
include 'ini.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>&#26080;&#26631;&#39064;&#25991;&#26723;</title>
</head>
<body>
<table border="1px">
<th><a href="form2.php">增</a></th>
<?php
$page=$_GET['page']?$_GET['page']:1;
$length=5;
//取user表总行数
$sql="select count(*) from hd_user";
$rows=mysql_query($sql);
$row=mysql_fetch_row($rows);
//$row[0] =24
$pagenum=ceil($row[0]/$length);
$offset=($page-1)*$length;
$sql="select * from hd_user order by id limit $offset,$length";
$prev=$page-1;
//页数不小于1
if($page<=1){
$prev=1;
}
$next=$page+1;
//页数不大于最大页数
if($page>=$pagenum){
$next=$pagenum;
}
$rows=mysql_query($sql);
while($row=mysql_fetch_row($rows)){
echo "<tr>";
echo "<td>$row[0]</td>";
echo "<td>$row[1]</td>";
echo "<td><a href='del.php?id=$row[0]'>删</a>|<a href='form.php?id=$row[0]&user=$row[1]'>改</a></td>";
echo "</tr>";
}
?>
</table>
<?php
echo "<h2><a href='index.php?page=1'>首页</a> | <a href='index.php?page={$prev}'>上一页</a> | <a href='index.php?page={$next}'>下一页</a> | <a href='index.php?page={$pagenum}'>末页</a> | 共{$pagenum}页</h2>"
?>
</body>
</html>


1楼2013-11-15 08:30回复
    非常非常感谢你!!我从8点开始纠结这个分页,找了数不清的网页终于弄好了,全靠你的两个if语句界限!


    IP属地:江苏2楼2015-04-27 21:59
    收起回复