首页 > 代码库 > 将上下页转换封装类

将上下页转换封装类

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
class page{
  var $table;
  var $pagesize;
  var $totalsize;
  var $totalpage;
  var $start;
  var $page;
  var $propage;
  var $xiapage;
  //var $div;
  //var $data;
  function __construct($table,$pagesize){
     $this->table=$table;
  $this->pagesize=$pagesize;
     $sql="select * from ".$table."";
  $query=mysql_query($sql);
  $this->page=isset($_GET[‘page‘])?$_GET[‘page‘]:1;
  $this->totalsize=mysql_num_rows($query);
  $this->totalpage=ceil(($this->totalsize)/($this->pagesize));
    $this->start=($this->pagesize)*($this->page-1);
    $this->propage=$this->page-1;
    $this->xiapage=$this->page+1;
  }
  function getrows(){
     $sqls="select * from ".$this->table." limit ".$this->start.",".$this->pagesize."";
  $querys=mysql_query($sqls);
  $datas=array();
  while($rows=mysql_fetch_array($querys)){
     $datas[]=$rows;
  }
  //print_r($data);
  //$this->data=http://www.mamicode.com/$datas;
  return $datas;
  }
  function getitem(){
     if(($this->page)<=1){
          $this->page=1;
        }
        if(($this->page)>($this->totalpage)){
          $this->page=$this->totalpage;
        }
     $div="<a href=http://www.mamicode.com/"?page=1\">    首页</a><a href=http://www.mamicode.com/"?page=$this->propage\">   上一页</a><a href=http://www.mamicode.com/"?page=$this->xiapage\">   下一页</a><a href=http://www.mamicode.com/"?page=$this->totalpage\">尾页</a>";
     return $div;
  }
 
}
 
 
?>

将上下页转换封装类