一个基于ADODB的分页类
<?php
class MyADOPager{
var $tablename;
var $curr_page;
var $conn;
var $page_size;
function __construct($conn,$tablename,$page_size,$curr_page=1){
$this->conn=$conn;
$this->tablename=$tablename;
$this->page_size=$page_size;
$this->curr_page=$curr_page;
}//end;
//此方法用于获取记录的总页数;
function getTotalPages(){
$str="select * from ".$this->tablename."";
$query_str=$this->conn->Execute($str);
$total_record=$query_str->RecordCount();
$total_pages=ceil($total_record/$this->page_size);
return $total_pages;
}//end;
//此方法用于获取每页的数据记录;
function getPageRecord($order,$where="",$start="0",$cols="*"){
$str_record="select ".$cols." from ".$this->tablename." ".$where." ".$order."";
$select=$this->conn->SelectLimit($str_record,$this->page_size,$start);
$res=$select->GetAll();
return $res;
}//end;
//此方法用于获取页码,left、right分别表示距离当前页的左范围和右范围;
function getPageLinks($curr_page,$left,$right){
$arr_pagelinks=array();
$this->curr_page=$curr_page;
$total=MyADOPager::getTotalPages();
if($this->curr_page<1){
$this->curr_page=1;
}
if($this->curr_page>$total){
$this->curr_page=$total;
}
if($this->curr_page==1){
array_push($arr_pagelinks,$this->curr_page);
$right_page_limit=$this->curr_page+$right;
if($right_page_limit>$total){
$right_page_limit=$total;
}
for($a=$this->curr_page+1;$a<=$right_page_limit;$a++){
$me=$_SERVER['PHP_SELF'];
$temp="<a href='".$me."?page=$a'>$a</a>";
array_push($arr_pagelinks,$temp);
}
//return $arr_pagelinks;
//exit();
}
if($this->curr_page==$total){
$left_page_limit=$this->curr_page-$left;
if($left_page_limit<1){
$left_page_limit=1;
}
for($b=$left_page_limit;$b<$this->curr_page;$b++){
$me=$_SERVER['PHP_SELF'];
$temp="<a href='".$me."?page=$b'>$b</a>";
array_push($arr_pagelinks,$temp);
}
array_push($arr_pagelinks,$this->curr_page);
//return $arr_pagelinks;
//exit();
}
if($this->curr_page>1 && $this->curr_page<$total){
$left_page_limit=$this->curr_page-$left;
$right_page_limit=$this->curr_page+$right;
if($left_page_limit<1){
$left_page_limit=1;
}
if($right_page_limit>$total){
$right_page_limit=$total;
}
for($c=$left_page_limit;$c<$this->curr_page;$c++){
$me=$_SERVER['PHP_SELF'];
$temp="<a href='".$me."?page=$c'>$c</a>";
array_push($arr_pagelinks,$temp);
}
array_push($arr_pagelinks,$this->curr_page);
for($d=$this->curr_page+1;$d<=$total;$d++){
$me=$_SERVER['PHP_SELF'];
$temp2="<a href='".$me."?page=$d'>$d</a>";
array_push($arr_pagelinks,$temp2);
}
//return $arr_pagelinks;
}
return $arr_pagelinks;
}//end;
}//end class;
?> ;