分页类
时间:2008-04-23 来源:小飞虫
功能:换页用物件
用法:
1.生成物件
$Chi_page= new Chi_Page(资料笔数,每页笔数,目前页数,连结网址) ;
2.秀出结果
echo $Chi_page->show_page();
page=0:$this->page=$page;
($url=='') ? $this->url=$_SERVER[PHP_SELF]:$this->url=$url;
$this->size=$size;
// ($size=='') ? die("无法操作Chi_Page class"):$this->size=$size ;
$this->tol=$tol;
// if ($this->tol==''|| $this->tol==0) die("没有资料,无法操作 Chi_Page class");
$this->all_p=ceil($this->tol/$this->size);
}
##################### 跳页函式 ###########################
function show_page(){
if ($this->tol=='' ||$this->tol==0 || $this->size==''|| $this->size==0 ){
return "目前无资料!";
}
$tol=$this->all_p;
$now=$this->page;
$URL=$this->url;
($URL==$_SERVER[PHP_SELF]) ? $ln='?':$ln='&';
if ( $tol==1 ) return "";
if ( $tol==2 ) {
if ($now==0) $tt= $this->button('第1页').$this->button('上页').$this->button('下页',$URL.$ln."page=1").$this->button('最末页',$URL.$ln."page=1");
if ($now==1) $tt= $this->button('第1页',$URL.$ln."page=0").$this->button('上页').$this->button('下页');
}
if ( $tol>=3) {
$tol2=$tol-1;
if ($now==0) $tt=$this->button('第1页').$this->button('上页').$this->button('下页',$URL.$ln."page=1").$this->button('最末页',$URL.$ln."page=".$tol2);
if ($now!=$tol2 && $now!=0)
$tt=$this->button('第1页',$URL.$ln."page=0").
$this->button('上页',$URL.$ln."page=".($now-1)).$this->button('下页',$URL.$ln."page=".($now+1)).$this->button('最末页',$URL.$ln."page=".$tol2);
if ($now==$tol2)
$tt= $this->button('第1页',$URL.$ln.'page=0').
$this->button('上页',$URL.$ln."page=".($now-1)).$this->button('下页').$this->button('最末页');
}
$ss=$this->jump($URL,$ln,$tol,$now);
Return $this->button("共 $this->tol 笔").$tt.$ss;
}
function jump($URL,$ln,$tol,$now){
$ss="";
for ($i=0;$i第".($i+1)."页\n";
}
$ss.="";
return $ss;
}
function button($word,$URL=''){
$tt="":$tt.=" onclick=\"location.href='$URL'\" >";
return $tt;
}
function button3($word,$URL=''){
$tt="":$tt.=" onclick=\"location.href='$URL'\" style=' background-color:#BFBFBF; font-size:10pt;color:blue;' >";
return $tt;
}
function button2($word,$URL=''){
$tt="":$tt.=" onclick=\"location.href='$URL'\" style=' background-color:#BFBFBF; font-size:10pt;color:blue;' >";
return $tt;
}
}
/*
####### -----用法
$size=10;//每页10笔
if ($_GET[page]=='') $Chi_page= new Chi_Page(500,$size,0) ;
else $page= new Chi_Page(500,$size,$_GET[page]) ;
echo $page->show_page();
*/
?>
相关阅读 更多 +