成都网站建设设计

将想法与焦点和您一起共享

php+pdo分页类-创新互联

class SepPage{
var $db; //pdo实例
var $sqlStr; //数据库查询语句
var $nowPg; //当前页
var $pageSize; //每页显示的记录数

function ShowPage($db, $sqlStr, $pageSize, $nowPg){
$this->db = $db;
$this->sqlStr = $sqlStr;
$this->pageSize = $pageSize;
if (!isset($nowPg) || ($nowPg == '') || ($nowPg == 0)){
$nowPg = 1;
}
$this->nowPg = $nowPg;
$start = $pageSize * ($nowPg - 1);
$sqlStr .= " limit ".$start." , ".$pageSize;
$rst = $db->query($sqlStr);
if ($db->errorCode() != '00000'){
print_r($db->errorInfo());
exit();
}
$rstArr = $rst->fetchAll();
return $rstArr;
}

function PageNav($name, $unit, $class){
$rst = $this->db->query($this->sqlStr);
if ($this->db->errorCode() != '00000'){
print_r($this->db->errorInfo());
exit();
}
$rstArr = $rst->fetchAll();
$recordCount = count($rstArr); //总的记录数
$lastPg = ceil($recordCount/$this->pageSize); //尾页,即总的页数
$lastPg = $lastPg ? $lastPg : 1; //没有显示条目,置最后页为1
$prePg = $this->nowPg - 1;
$nextPg = (($this->nowPg == $lastPg) ? 0 : ($this->nowPg + 1));

if ($lastPg <= 1){
return false;
}

$str = "共有".$name." ".$recordCount." ".$unit.",每页显示 ".$this->pageSize." ".$unit.",第 ".$this->nowPg." 页/共 ".$lastPg." 页,";
$str .= "到第页";

$str .= "    ";

if ($prePg){
$str .= "首页";
$str .= " ";
$str .= "上一页";
$str .= " ";
}else{
$str .= "首页";
$str .= " ";
$str .= "上一页";
$str .= " ";
}

if ($nextPg){
$str .= "下一页";
$str .= " ";
$str .= "尾页";
$str .= "    ";
}else{
$str .= "下一页";
$str .= " ";
$str .= "尾页";
$str .= "    ";
}
return $str;
}
}
?>

在弋江等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计制作、成都网站设计 网站设计制作按需网站策划,公司网站建设,企业网站建设,品牌网站制作,成都全网营销,外贸营销网站建设,弋江网站建设费用合理。
网页标题:php+pdo分页类-创新互联
当前地址:http://chengdu.cdxwcx.cn/article/jdidi.html