工会web
This commit is contained in:
66
GonghuiWeb/class/myPage.php
Normal file
66
GonghuiWeb/class/myPage.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
//通用分页类
|
||||
class myPage extends myConn{
|
||||
function getpage($field,$table,$where,$order='',$pageSize=10,$linkNum=7,$page=1,$conn=''){
|
||||
if($conn) $this->links($conn);
|
||||
if(!preg_match('/^[0-9]+$/i',$page) || !$page) $page=1;
|
||||
|
||||
$sql="select $field from $table ";
|
||||
if($where){ $sql.=" WHERE $where "; }
|
||||
if($order){ $sql.=" order by $order "; }
|
||||
$totalNum=$this->getcount($sql);//总数
|
||||
$rs=$this->query($sql);
|
||||
$maxPage = (int)ceil($totalNum/$pageSize); //得到最大页码数 $maxPage
|
||||
if((int)$page>$maxPage) $page=$maxPage;
|
||||
if(mssql_data_seek($rs,($page-1)*$pageSize)){
|
||||
for($p=0;$p<$pageSize;$p++){
|
||||
$row=$this->getfetch($rs);
|
||||
$Snum=$totalNum-$p-($pageSize*$page)+$pageSize;//序列号
|
||||
if($row) $rot[]=$row+array("Snum"=>$Snum);
|
||||
}
|
||||
}
|
||||
$this->start=($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1";
|
||||
$this->end=($page+round($linkNum/2))<$maxPage ? ($page+round($linkNum/2)) : $maxPage;
|
||||
$this->maxPage=$maxPage;//最大页码
|
||||
$this->pageSize=$pageSize;//每页显示
|
||||
$this->linkNum=$linkNum;//链接显示数
|
||||
$this->totalNum=$totalNum;//总数
|
||||
$this->page=$page;//当前页
|
||||
return $rot;
|
||||
unset($sql,$rs,$row,$rot);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
|
||||
function getpages($sql,$pageSize=10,$linkNum=7,$page=1,$conn=''){
|
||||
if($conn) $this->links($conn);
|
||||
if(!preg_match('/^[0-9]+$/i',$page) || !$page) $page=1;
|
||||
$totalNum=$this->getcount($sql);//总数
|
||||
$rs=$this->query($sql);
|
||||
$maxPage = (int)ceil($totalNum/$pageSize); //得到最大页码数 $maxPage
|
||||
if((int)$page>$maxPage) $page=$maxPage;
|
||||
if(mssql_data_seek($rs,($page-1)*$pageSize)){
|
||||
for($p=0;$p<$pageSize;$p++){
|
||||
$row=$this->getfetch($rs);
|
||||
$Snum=$totalNum-$p-($pageSize*$page)+$pageSize;//序列号
|
||||
if($row) $rot[]=$row+array("Snum"=>$Snum);
|
||||
}
|
||||
}
|
||||
$this->start=($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1";
|
||||
$this->end=($page+round($linkNum/2))<$maxPage ? ($page+round($linkNum/2)) : $maxPage;
|
||||
$this->maxPage=$maxPage;//最大页码
|
||||
$this->pageSize=$pageSize;//每页显示
|
||||
$this->linkNum=$linkNum;//链接显示数
|
||||
$this->totalNum=$totalNum;//总数
|
||||
$this->page=$page;//当前页
|
||||
return $rot;
|
||||
unset($sql,$rs,$row,$rot);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
function getpagecs(){ //获取分页参数
|
||||
$myarray = array('Page'=>$this->page,'Start'=>$this->start,'End'=>$this->end,'maxPage'=>$this->maxPage,'pageSize'=>$this->pageSize,'linkNum'=>$this->linkNum,'totalNum'=>$this->totalNum);
|
||||
return $myarray;
|
||||
}
|
||||
function __destruct(){//释放类
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user