国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > PHP > 正文

php pdo分頁(yè)同時(shí)支持mysql和access

2024-09-04 11:32:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

access是不支持limit分頁(yè)的,想同的關(guān)鍵,問(wèn)題馬上就解決了。

看注釋?xiě)?yīng)該很容易理解,access的分頁(yè)sql從asp json 的google code上來(lái)的 

<?php/** //分頁(yè)類 */class Page{ //字段屬性 public $param; //分頁(yè)參數(shù) public $pagesize; //每頁(yè)大小 public $sql;//當(dāng)數(shù)據(jù)庫(kù)為access,無(wú)效 public $conn; //設(shè)置數(shù)據(jù)庫(kù)類型 public $dbtype; //當(dāng)數(shù)據(jù)庫(kù)為access配置項(xiàng) 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(){ } //開(kāi)始 public function getStart(){  //$param=$this->param;  $param=(isset($_GET[$this->param])) ? $_GET[$this->param] : 1;  return ($param-1) * $this->pagesize; } //生成SQL語(yǔ)句 //mysql public function getMysqlSql(){  return $this->sql . " limit " . $this->getStart() ."," .$this->pagesize . "";  //return "test"; } //access的查詢語(yǔ)句,參考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; } //獲取總頁(yè)數(shù) public function getPageCount(){  return $this->getRecordCount() / $this->pagesize; } //獲取總記錄數(shù) public function getRecordCount(){  $rs=$this->conn->query("select count(*) from [" .$this->tbname ."]");  $row=$rs->fetchColumn();  return $row; } //獲取分頁(yè)導(dǎo)航 public function getPageTool(){  $pagecount= round($this->getPageCount());  $param=(isset($_GET[$this->param])) ? $_GET[$this->param] : 1;  if($param<=1){   echo "首頁(yè) 上一頁(yè) ";  }else{   echo "<a href='?".$this->param."=1'>首頁(yè)</a> <a href='?".$this->param."=".($param-1)."'>上一頁(yè)</A> ";  }  if($param>=$pagecount){   echo "下一頁(yè) 尾頁(yè)";  }else{   echo "<A href='?".$this->param."=".($param+1)."'>下一頁(yè)</A> <A href='?".$this->param."=".$pagecount."'>尾頁(yè)</A>";  } }}?>
上一篇:php驗(yàn)證碼

下一篇:php分頁(yè)類

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江达县| 遂平县| 积石山| 株洲县| 迭部县| 子长县| 青海省| 莆田市| 买车| 马山县| 大宁县| 舒城县| 子洲县| 凉城县| 福清市| 赤壁市| 陇川县| 绵阳市| 伊金霍洛旗| 图木舒克市| 棋牌| 小金县| 临武县| 湖口县| 玉龙| 郁南县| 城市| 鄂托克旗| 杨浦区| 平泉县| 灵宝市| 枝江市| 九寨沟县| 阿瓦提县| 新和县| 理塘县| 太白县| 泰安市| 柞水县| 平阳县| 怀远县|