这是一款php分页程序,一款数字分页代码,很像搜索引擎baidu的分页效果,有需要做这类分页的朋友可进入参考,php分页代码如下:
- <?php
- $conn=mysql_connect("localhost","root","");
- $db=mysql_select_db("gan");
- mysql_query("set names 'gbk'");
- ?>
- <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html xmlns="http://www.111cn.net/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title>无标题文档</title>
- </head>
-
- <body>
- <?php
-
- $url=$_server['request_uri'];
- $url=parse_url($url);
- $url=$url[path];
- $sql="select * from liuyan";
- $query=mysql_query($sql);
- $num=mysql_num_rows($query);
- $pagesize=3;
- $pages=intval($num/$pagesize);
- if($num%$pagesize){
- $pages++;
- }
-
- $page=1;
-
- if($_get[page]){
- $page=$_get[page];
- }
- $fistpage=1;
- $prepage=$page-1;
- $lastpage=$pages;
- $nextpage=$page+1;
- $n=1;
- $pack=1;
- $perpage=intval($pages/5);
- if($pages%5){
- $perpage++;
- }
- if($page>1){
- echo "<a href=$url?page=$fistpage>第一页</a>";
- echo "<a href=$url?page=$prepage>上一页</a>";
- }
- if($page-$pack>=5){
- $n++;
- $pack+=5;
- for($i=($n*5-4);$i<$page;$i++){
- echo "<a href=$url?page=$i> $i </a>";
- }
- echo $i;
- if($n<$perpage){
- for($i=$i+1;$i<=$n*5;$i++)
- echo "<a href=$url?page=$i> $i </a>";
- }else{
- for($i=$i+1;$i<=$pages;$i++)
- echo "<a href=$url?page=$i> $i </a>";
- }
-
- }
- else{
- for($i=($n*5-4);$i<$page;$i++)
- echo "<a href=$url?page=$i> $i </a>";
- echo $i;
- if($n<$perpage){
- for($i=$i+1;$i<=$n*5;$i++)
- echo "<a href=$url?page=$i> $i </a>";
- }else{
- for($i=$i+1;$i<=$pages;$i++)
- echo "<a href=$url?page=$i> $i </a>";
- }
-
-
-
- }
- if($page<$pages){
-
- echo "<a href=$url?page=$nextpage>下一页</a>";
- echo "<a href=$url?page=$lastpage>最后一页</a>";
- }
- $offnum=($page-1)*$pagesize;
- $fsql="select * from liuyan limit $offnum,$pagesize";
- $query=mysql_query($fsql);
- while($row=mysql_fetch_array($query)){
-
- echo "<br>".$row[user]."|".$row[content];
- }
- ?>
- </body>
- </html>
|