//定每页显示多少条 //count(*)查询总条数 //计算总页数ceil() //判断$_GET 并赋值当前页数 //mysql查询 limit (当前页数-1)*每页条数,每页条数 //如果总条数不为空,进行循环mysql_fetch_array() //$_SERVER['PHP_SELF'] //上一页?page=当前页-1 //下一页?page=当前页+1 //edit: bbs.it-home.org include("conn.php"); $perpagenum = 3; $total = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM message")); $Total = $total[0]; $Totalpage =ceil($Total/$perpagenum); if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET['page']>$Totalpage){ $page = 1; }else{ $page = $_GET['page']; } $start = ($page-1)*$perpagenum; $sql = "SELECT * FROM message ORDER BY id DESC LIMIT $start,$perpagenum"; $result = mysql_query($sql); $contents = mysql_fetch_array($result); ?> if($total){ do{ $user = $contents['user']; $contact = $contents['contact']; $content = $contents['content']; $date = $contents['date']; ?> 昵称: 发表于: } //php分页开始 while($contents=mysql_fetch_array($result)); $per = $page-1; $next= $page+1; echo "共有".$Total."条留言,每页".$perpagenum."条,共".$page."/".$Totalpage."页。";if($page!=1){ echo "首页". "上一页"; } if($page!=$Totalpage){ echo "下一页"; echo "尾页"; } ?> } ?> 复制代码