- ·上一篇内容:zend studio 7.2.0如何整合flex的功能
- ·下一篇内容:php分页类
php pdo分页同时支持mysql和access
access是不支持limit分页的,想同的关键,问题马上就解决了。
看注释应该很容易理解,access的分页sql从asp json 的google code上来的
<?php
/**
//分页类
*/
class Page{
//字段属性
public $param; //分页参数
public $pagesize; //每页大小
public $sql;//当数据库为access,无效
public $conn;
//设置数据库类型
public $dbtype;
//当数据库为access配置项
public $tbname;//表名
public $prikey;//主键
//public $url;
public function __set($name,$value){
$this->$name = $value;
}
//初始化
public function __construct(){
//$this->conn=new mysqli("localhost","root","147258","empirecms");
//$this->conn->set_charset('utf8');
}
//销毁
public function __destruct(){
}
//开始
public function getStart(){
//$param=$this->param;
$param=(isset($_GET[$this->param])) ? $_GET[$this->param] : 1;
return ($param-1) * $this->pagesize;
}
//生成SQL语句
//mysql
public function getMysqlSql(){
return $this->sql . " limit " . $this->getStart() ."," .$this->pagesize . "";
//return "test";
}
//access的查询语句,参考json asp google
public function getAccessSql(){
$end_n=$this->getStart() + $this->pagesize;
if($end_n>$this->pagesize){
$accsql = "SELECT TOP ". $this->pagesize ." * FROM [" . $this->tbname . "] as a where Not Exists(Select * From (Select Top ". $this->getStart() ." * From [" . $this->tbname . "] order by [" . $this->prikey . "] DESC) b Where b.[" . $this->prikey . "]=a.[" . $this->prikey . "] ) ORDER BY a.[" . $this->prikey . "] DESC" ;
}else{
$accsql = "SELECT TOP ". $this->pagesize ." * FROM [" . $this->tbname . "] ORDER BY [" . $this->prikey . "] DESC" ;
}
return $accsql;
}
//获取记录
public function getRecordSet(){
switch($this->dbtype){
case "ACCESS":
$ssql=$this->getAccessSql();
break;
case "MYSQL":
$ssql=$this->getMysqlSql();
break;
}
$rs1=$this->conn->query($ssql);
return $rs1;
}
//获取总页数
public function getPageCount(){
return $this->getRecordCount() / $this->pagesize;
}
//获取总记录数
public function getRecordCount(){
$rs=$this->conn->query("select count(*) from [" .$this->tbname ."]");
$row=$rs->fetchColumn();
return $row;
}
//获取分页导航
public function getPageTool(){
$pagecount= round($this->getPageCount());
$param=(isset($_GET[$this->param])) ? $_GET[$this->param] : 1;
if($param<=1){
echo "首页 上一页 ";
}else{
echo "<a href='?".$this->param."=1'>首页</a> <a href='?".$this->param."=".($param-1)."'>上一页</A> ";
}
if($param>=$pagecount){
echo "下一页 尾页";
}else{
echo "<A href='?".$this->param."=".($param+1)."'>下一页</A> <A href='?".$this->param."=".$pagecount."'>尾页</A>";
}
}
}
?>本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论
