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