Home  >  Article  >  php教程  >  分页类12

分页类12

PHP中文网
PHP中文网Original
2016-05-25 16:58:421209browse

跳至

 /*分页类*/
  class DividePage//分页类
  {
    private $start;//起始位置
    private $size;//每页欲显示的条数
    private $list;//欲查询的数据库表	
	private $rows;//数据库表的总条数
	private $lastpage;//表的尾页
    function __construct($start,$size,$db_list)
	{
	   $this->start=$start;
	   $this->size=$size;
	   $this->db_list=$db_list;
	   if(!isset($_GET['count_rows']))//为了提高效率,计算条数只需要一次。
	   {
	      $Model=new Model();//实例化模型,使用原生SQL查询
	      $row=$Model->query('SELECT count(*) FROM Studentlist');
	      $this->rows=current(current($row));	 
		  $this->lastpage=$this->rows-($this->rows%$this->size);
       }	   
	}  
	function GetResult()//查询数据库,找出指定的返回结果
	{  
	   $Obj=D($this->db_list);//实例化模型
	   $sql=$this->start.",".$this->size;
	   $result=$Obj->limit($sql)->select();
	   return $result;
	}
	function GetOption()//返回一个数组,在模板里面遍历生成下拉列表
	{
	   return $this->size;
	}
	function GetRows()//获取表的总条数
	{
	   $Model=new Model();//实例化模型,使用原生SQL查询
	   $row=$Model->query('SELECT count(*) FROM Studentlist');
	   $this->rows=current(current($row));	  
	}
	//翻页的原则是
	function GetBackStart()//上一页
	{
	   if($this->start==0)
	      return $this->start;
	   else
	      return ($this->start)-($this->size);
	}
	function GetForwardStart()//下一页
	{
	   if($this->start==$this->lastpage)
	     return $this->start;
	   else
	     return ($this->start)+($this->size); 
	}
	function GetLastPage()
	{
	    return $this->lastpage;
	}
  }
  /*分页类END*/

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn