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] ); return $page_info; } } } |