ADODB+SMARTY的一个PHP分页类(带搜索分页)
[code]
table=$table;
$all=$conn->GetAll($sql);
$this->num=count($all);
return $this->num;
}
function Getallpage($n){//得到一共几页
$this->n=$n;
$this->j=ceil($this->num/$this->n);
return $this->j;
}
function Getpage($d,$url){//分页
$d=$_GET[‘page’];
$this->d=$d;
$this->url=$url;
if (empty($this->d) || $this->d <0 || $this->d==0 || $this->d==1){
$this->d=1;
if(($this->j)>1){
$str=”首页”;
$str.=$this->mathurl(2,5);
$str.=”url.”page=”.($this->d-1).”‘>上一页“;
$str.=$this->mathurl(2,5);
$str.=”尾页”;
}else{
$str=”url.”page=”.($this->d+1).”‘>下一页“;
}
return $str;
return $this->d;
return $this->url;
}
function Getstart(){//起始位置
if(empty($this->d)){
$this->start=0;
}else{
$this->start=$this->n*($this->d-1);
}
return $this->start;
}
function Getend($e){//每页显示条数
return $this->d=$e;
}
function options(){//跳转菜单
$opt=” url.”page=”.$o.”‘>”.$o.” “;
}
}elseif($co>($do-$this->py)){//页码超过总页数时
$co=$do;
for ($v=($co-($this->yc-1));$v<=$do;$v++){//往左偏移$yc个单位 $murl.=" url.”page=”.$v.”‘>”.$v.” “;
}
}else{
for($k=($co-$this->py);$k<$co;$k++){//往左偏移$py个单位 $murl.=" url.”page=”.$v.”‘>”.$v.” “;
}
}
return $murl;
}
}/*
require_once(“../class/Smarty.class.php”);
include “../adodb/adodb.inc.php”;
include “../connect.php”;
$page=new Page();
$sql=”select * from class”;
$p[‘num’]=$page->Getallnum($sql);
$p[‘page’]=$page->Getallpage(10);
$p[‘link’]=$page->Getpage(1,”class.inc.php?”);
$p[‘start’]=$page->Getstart(0);
$p[‘end’]=$page->Getend(10);
$p[‘opt’]=$page->options();
$a=$conn->GetAll(“select * from class limit “.$p[‘start’].”,”.$p[‘end’].””);
————————–上面的是数据库分页的例子——————————-
————————–下面的是搜索分页的例子————————————–
$s=$_GET[‘s’];
$si=$_POST[‘s’];
if(empty($_GET[‘key’])){
$key=$si;
}else{
$key=$_GET[‘key’];
}
if($s==”s”){
$page=new Page();
$sqa=”select cname from class where cname like binary ‘%”.$key.”%'”;
$p[‘num’]=$page->Getallnum($sqa);
$p[‘page’]=$page->Getallpage(6);
$p[‘link’]=$page->Getpage(1,”class.inc.php?s=s&key=”.$key.”&”);
$p[‘start’]=$page->Getstart(0);
$p[‘end’]=$page->Getend(6);
$sql=”select cname from class where cname like binary ‘%”.$key.”%’ limit “.$p[‘start’].”,”.$p[‘end’].””;
$rs=$conn->GetAll($sql);
}
————————-下面的是smarty应用————————————————-
$smarty = new Smarty;
$smarty->assign(“page”,$p);
$smarty->assign(“show”,$a);
//$smarty->assign(“se”,$rs);
$smarty->display(‘class.inc.htm’);
*/
?> [/code]
$all=$conn->GetAll($sql);
$this->num=count($all);
return $this->num;
}
function Getallpage($n){//得到一共几页
$this->n=$n;
$this->j=ceil($this->num/$this->n);
return $this->j;
}
function Getpage($d,$url){//分页
$d=$_GET[‘page’];
$this->d=$d;
$this->url=$url;
if (empty($this->d) || $this->d <0 || $this->d==0 || $this->d==1){
$this->d=1;
if(($this->j)>1){
$str=”首页”;
$str.=$this->mathurl(2,5);
$str.=”url.”page=”.($this->d-1).”‘>上一页“;
$str.=$this->mathurl(2,5);
$str.=”尾页”;
}else{
$str=”url.”page=”.($this->d+1).”‘>下一页“;
}
return $str;
return $this->d;
return $this->url;
}
function Getstart(){//起始位置
if(empty($this->d)){
$this->start=0;
}else{
$this->start=$this->n*($this->d-1);
}
return $this->start;
}
function Getend($e){//每页显示条数
return $this->d=$e;
}
function options(){//跳转菜单
$opt=” url.”page=”.$o.”‘>”.$o.” “;
}
}elseif($co>($do-$this->py)){//页码超过总页数时
$co=$do;
for ($v=($co-($this->yc-1));$v<=$do;$v++){//往左偏移$yc个单位 $murl.=" url.”page=”.$v.”‘>”.$v.” “;
}
}else{
for($k=($co-$this->py);$k<$co;$k++){//往左偏移$py个单位 $murl.=" url.”page=”.$v.”‘>”.$v.” “;
}
}
return $murl;
}
}/*
require_once(“../class/Smarty.class.php”);
include “../adodb/adodb.inc.php”;
include “../connect.php”;
$page=new Page();
$sql=”select * from class”;
$p[‘num’]=$page->Getallnum($sql);
$p[‘page’]=$page->Getallpage(10);
$p[‘link’]=$page->Getpage(1,”class.inc.php?”);
$p[‘start’]=$page->Getstart(0);
$p[‘end’]=$page->Getend(10);
$p[‘opt’]=$page->options();
$a=$conn->GetAll(“select * from class limit “.$p[‘start’].”,”.$p[‘end’].””);
————————–上面的是数据库分页的例子——————————-
————————–下面的是搜索分页的例子————————————–
$s=$_GET[‘s’];
$si=$_POST[‘s’];
if(empty($_GET[‘key’])){
$key=$si;
}else{
$key=$_GET[‘key’];
}
if($s==”s”){
$page=new Page();
$sqa=”select cname from class where cname like binary ‘%”.$key.”%'”;
$p[‘num’]=$page->Getallnum($sqa);
$p[‘page’]=$page->Getallpage(6);
$p[‘link’]=$page->Getpage(1,”class.inc.php?s=s&key=”.$key.”&”);
$p[‘start’]=$page->Getstart(0);
$p[‘end’]=$page->Getend(6);
$sql=”select cname from class where cname like binary ‘%”.$key.”%’ limit “.$p[‘start’].”,”.$p[‘end’].””;
$rs=$conn->GetAll($sql);
}
————————-下面的是smarty应用————————————————-
$smarty = new Smarty;
$smarty->assign(“page”,$p);
$smarty->assign(“show”,$a);
//$smarty->assign(“se”,$rs);
$smarty->display(‘class.inc.htm’);
*/
?> [/code]
