Home > php教程 > PHP源码 > body text

分页类12

PHP中文网
Release: 2016-05-25 16:58:42
Original
1207 people have browsed it

跳至

 /*分页类*/
  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*/
Copy after login

                   

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template