php分页代码
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-16 22:39:32 浏览: 评论:0
这是一款简单实用的php分页代码,同时也很好的利用的类的构造函数来实例分页的初始化,好了下面我们来看看这款代码如何吧,代码如下:
- class page extends mysql
- {
- public $page;
- public $page_size;
- private $table;
- private $condition;
- private $limit;
- private $href;
- private $action_value;
- private $url_value;
- //分页初始化
- function __construct($page,$page_size,$table,$condition,$limit,$href,$action_value,$url_value)
- {
- $this->page=$page;
- $this->page_size=$page_size;
- $this->table=$table;
- $this->condition=$condition;
- $this->limit=$limit;
- $this->href=$href;
- $this->action_value=$action_value;
- $this->url_value=$url_value;
- $this->get_page();
- }
- /**
- * get the page's value判断当前在第几页
- */
- function get_page()
- {
- if($this->page=="")
- {
- $this->page=1;
- }
- return $this->page;
- }
- /**
- * page main code //调用转到指定的分页代码号。
- */
- function go_page()
- {
- if($this->page!="")
- {
- $reslut=mysql::fn_select($this->table,'count(*) as `total`',$this->condition,'',$this->limit);
- $rs=mysql::fetch_array($reslut);
- $message_count=$rs['total']; //get the messages's count number
- $page_count=ceil($message_count/$this->page_size); //get the page's count number
- $offset=($this->page-1)*$this->page_size; //get the first value of sql's limit
- if($message_count<=$this->page_size)
- {
- $page_code=array("","","","");
- }
- else if($this->page==1)
- {
- $page_code=array("",
- "",
- "<a name=code href=".$this->href."?page=".($this->page+1)."&action=".$this->action_value."&".$this->url_value.">下一页</a>",
- "<a name=code href=".$this->href."?page=".$page_count."&action=".$this->action_value."&".$this->url_value.">尾页</a>");
- }
- else if($this->page==$page_count)
- {
- $page_code=array("<a name='code' href=".$this->href."?page=1&action=".$this->action_value."&".$this->url_value.">首页</a>",
- "<a name='code' href=".$this->href."?page=".($this->page-1)."&action=".$this->action_value."&".$this->url_value.">上一页</a>",
- "",
- "");
- }
- else
- {
- $page_code=array("<a name='code' href=".$this->href."?page=1&action=".$this->action_value."&".$this->url_value.">首页</a>",
- "<a name='code' href=".$this->href."?page=".($this->page-1)."&action=".$this->action_value."&".$this->url_value.">上一页</a>",
- "<a name='code' href=".$this->href."?page=".($this->page+1)."&action=".$this->action_value."&".$this->url_value.">下一页</a>",
- "<a name='code' href=".$this->href."?page=".$page_count."&action=".$this->action_value."&".$this->url_value.">尾页</a>");
- }
- $page_info=array(
- "message_count"=>$message_count,
- "page_count"=>$page_count,
- "offset"=>$offset,
- "page_size"=>$this->page_size,
- "page_now"=>$this->page,
- "page_first"=>$page_code[0],
- "page_up"=>$page_code[1],
- "page_next"=>$page_code[2],
- "page_one_last"=>$page_code[3]
- );//开源代码phpfensi.com
- return $page_info;
- }
- }
- }
php分页代码调用方法,代码如下:
- $page = new page('',10,'`cy0871_users_info`','index.php',1,'','','userid=1');
- print_r ($page->go_page());
- $page_info = $page->go_page();
- echo $page_info['page']."<br/>";
- echo $page_info['page_size'];
Tags: php分页代码
- 上一篇:php分页代码(下一页 上一页)
- 下一篇:php 带条件查询 分页代码
相关文章
- ·php分页代码与分页原理(2013-11-12)
- ·简单入门级php分页代码(2014-05-10)
- ·两款实用php分页代码(2014-08-15)
- ·经典php分页代码,支持数字偏移(2014-08-15)
- ·php分页代码(实用的分页程序)(2014-08-16)
- ·php分页代码(下一页 上一页)(2014-08-16)
- ·php简单分页实例程序代码详解(2014-09-22)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)