本篇內(nèi)容主要講解“php分頁的實現(xiàn)方法有幾種”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“php分頁的實現(xiàn)方法有幾種”吧!
創(chuàng)新互聯(lián)公司是專業(yè)的華龍網(wǎng)站建設公司,華龍接單;提供成都做網(wǎng)站、成都網(wǎng)站設計,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行華龍網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
1、通過“MySQL_query”等函數(shù)將sql查詢進行分頁。
2、使用ajax的方法實現(xiàn)分頁。
3、通過“function viewpage(p){...}”腳本實現(xiàn)分頁。
實例
_conn === false || !is_resource($this->_conn)) { warningLog(__METHOD__ . ': query sql with no connection', true); return false; } $this->_query_id = @mysql_query($query, $this->_conn); if ($this->_query_id === false) { $this->_errstr = @mysql_error(); $ret = false; } else { $this->_errstr = 'SUCCESS'; $ret = $this->_query_id; } } $msg = ($ret === false) ? 'false' : strval($ret); debugLog(__METHOD__.": [$msg] returned for sql query [$query]"); return $ret; } function __construct($sql,$page_size) { $result = mysql_query($sql); $datanum = mysql_num_rows($result); $this->sql=$sql; $this->datanum=$datanum; $this->page_size=$page_size; } //當前頁數(shù) public function page_id() { if($_SERVER['QUERY_STRING'] == ""){ return 1; }elseif(substr_count($_SERVER['QUERY_STRING'],"page_id=") == 0){ return 1; }else{ return intval(substr($_SERVER['QUERY_STRING'],8)); } } //剩余url值 public function url() { if($_SERVER['QUERY_STRING'] == ""){ return ""; }elseif(substr_count($_SERVER['QUERY_STRING'],"page_id=") == 0){ return "&".$_SERVER['QUERY_STRING']; }else{ return str_replace("page_id=".$this->page_id(),"",$_SERVER['QUERY_STRING']); } } //總頁數(shù) public function page_num() { if($this->datanum == 0){ return 1; }else{ return ceil($this->datanum/$this->page_size); } } //數(shù)據(jù)庫查詢的偏移量 public function start() { return ($this->page_id()-1)*$this->page_size; } //數(shù)據(jù)輸出 public function sqlquery() { return $this->sql." limit ".$this->start().",".$this->page_size; } //獲取當前文件名 private function php_self() { return $_SERVER['PHP_SELF']; } //上一頁 private function pre_page() { if ($this->page_id() == 1) { //頁數(shù)等于1 return "url().">上一頁 "; }elseif ($this->page_id() != 1) { //頁數(shù)不等于1 return "上一頁 "; } } //顯示分頁 private function display_page() { $display_page = ""; if($this->page_num() <= 10){ //小于10頁 for ($i=1;$i<=$this->page_num();$i++) //循環(huán)顯示出頁面 $display_page .= "".$i." "; return $display_page; }elseif($this->page_num() > 10){ //大于10頁 if($this->page_id() <= 6){ for ($i=1;$i<=10;$i++) //循環(huán)顯示出頁面 $display_page .= "".$i." "; return $display_page; }elseif(($this->page_id() > 6) && ($this->page_num()-$this->page_id() >= 4)){ for ($i=$this->page_id()-5;$i<=$this->page_id()+4;$i++) //循環(huán)顯示出頁面 $display_page .= "".$i." "; return $display_page; }elseif(($this->page_id() > 6) && ($this->page_num()-$this->page_id() < 4)){ for ($i=$this->page_num()-9;$i<=$this->page_num();$i++) //循環(huán)顯示出頁面 $display_page .= "".$i." "; return $display_page; } } } //下一頁 private function next_page() { if ($this->page_id() < $this->page_num()) { //頁數(shù)小于總頁數(shù) return "下一頁 "; }elseif ($this->page_id() == $this->page_num()) { //頁數(shù)等于總頁數(shù) return "下一頁 "; } } // 設置分頁信息 public function set_page_info() { $page_info = "共".$this->datanum."條 "; $page_info .= "url().">首頁 "; $page_info .= $this->pre_page(); $page_info .= $this->display_page(); $page_info .= $this->next_page(); $page_info .= "尾頁 "; $page_info .= "第".$this->page_id()."/".$this->page_num()."頁"; return $page_info; } } ?>
到此,相信大家對“php分頁的實現(xiàn)方法有幾種”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!