class Page{//分页类
var $table;//表名
var $n;//每页显示条数
var $d;//当前页
var $num;//总条数
var $j;//一共几页
var $start;//起始位置
var $url;//当前文件
var $py;//偏移几个单位,以当前页为中心对称偏移
var $yc;//溢出多少个单位,以3,5,7.....
function Getallnum($sql){//得到总条数
global $conn;
$this->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.="下一页";
}
}elseif(($this->d)>=$this->j){
$this->d=$this->j;
$str="上一页";
$str.=$this->mathurl(2,5);
$str.="尾页";
}else{
$str="上一页";
$str.=$this->mathurl(2,5);
$str.="下一页";
}
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=" ";
return $opt;
}
function mathurl($py,$yc){//数字导航
$this->py=$py;
$this->yc=$yc;
$co=$_GET['page'];//当前页码
$do=$this->j;//总页数
if($this->j<=$this->yc){//总页数小于或等于$yc时
for ($o=1;$o<=$this->j;$o++){
$murl.=" ".$o." ";
}
}elseif($co>($do-$this->py)){//页码超过总页数时
$co=$do;
for ($v=($co-($this->yc-1));$v<=$do;$v++){//往左偏移$yc个单位
$murl.=" ".$v." ";
}
}elseif($co<=$this->py){
$co=1;
for ($v=$co;$v<($co+$this->yc);$v++){//往右偏移$yc个单位
$murl.=" ".$v." ";
}
}else{
for($k=($co-$this->py);$k<$co;$k++){//往左偏移$py个单位
$murl.=" ".$k." ";
}
for ($v=$co;$v<=($co+$this->py);$v++){//往右偏移$py个单位
$murl.=" ".$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');
*/
?>
var $table;//表名
var $n;//每页显示条数
var $d;//当前页
var $num;//总条数
var $j;//一共几页
var $start;//起始位置
var $url;//当前文件
var $py;//偏移几个单位,以当前页为中心对称偏移
var $yc;//溢出多少个单位,以3,5,7.....
function Getallnum($sql){//得到总条数
global $conn;
$this->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.="下一页";
}
}elseif(($this->d)>=$this->j){
$this->d=$this->j;
$str="上一页";
$str.=$this->mathurl(2,5);
$str.="尾页";
}else{
$str="上一页";
$str.=$this->mathurl(2,5);
$str.="下一页";
}
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=" ";
return $opt;
}
function mathurl($py,$yc){//数字导航
$this->py=$py;
$this->yc=$yc;
$co=$_GET['page'];//当前页码
$do=$this->j;//总页数
if($this->j<=$this->yc){//总页数小于或等于$yc时
for ($o=1;$o<=$this->j;$o++){
$murl.=" ".$o." ";
}
}elseif($co>($do-$this->py)){//页码超过总页数时
$co=$do;
for ($v=($co-($this->yc-1));$v<=$do;$v++){//往左偏移$yc个单位
$murl.=" ".$v." ";
}
}elseif($co<=$this->py){
$co=1;
for ($v=$co;$v<($co+$this->yc);$v++){//往右偏移$yc个单位
$murl.=" ".$v." ";
}
}else{
for($k=($co-$this->py);$k<$co;$k++){//往左偏移$py个单位
$murl.=" ".$k." ";
}
for ($v=$co;$v<=($co+$this->py);$v++){//往右偏移$py个单位
$murl.=" ".$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');
*/
?>
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/499/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表