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>"; } }}?>
新聞熱點
疑難解答