-
-
/**************************************
- file: class.paging.php
- php分頁類別代碼
- **************************************/
- 類別分頁{
-
- var $sql_results;
- var $🎜>var $ sql_query;
-
- var $display_offset;
- var $display_limit;
- var $display_limit_URI;
- var $display_currentpage;
- var $display__o_f;
- var $display_offset_var;
- var $display_limit_var;
-
- var $display_mid_offset;
- var $display_link_first;
- var $display_olink_o_link_link_link_nlink_ovar display_link_last;
-
- var $page_filename;
- var $page_uri;
-
- var $content;
- var $content_type;
- var $content_count #
- #🎜> # 埃國定利
- 定利分頁($offsetVar='offset',$limit=10,$midOffset=2){
- $this->display_offset = isset($_REQUEST[$offsetVar])?$_REQUESToffset = isset($_REQUEST[$offsetVar])?$_REQUEST [ $ offsetVar]:0;
- $this->display_limit = is_numeric($limit)?$limit:10;
- $this->display_mid_offset = $midOffset;
- $this->display_offset_var = $offsetVar ;
- $this->display_currentpage= ceil($this->display_offset / $this->display_limit);
- }
-
- ## 電視安全於
- function setContent( $content){
- if( is_array($content) )
- $this->content_type = 'array';
-
- $this->content = $content;
- $this ->private_contentDetails();
- $this->getLinks();
- }
-
- function private_contentDetails(){
- if( $this->content_type == 'array' )
- $this->content_count$this->content_count = count( $this->content);
- }
-
- function getContent(){
- $returnAry = array();
- for (
- $i=$this->顯示偏移量;
- $icontent_count, $this->display_offset $this->display_limit );
- $i
- )
- array_push($returnAry,$this->content[$ i] );
-
- return $returnAry;
- }
-
- ## 導航連結
- function getLinks(){
- $this->getNextLink('');
- $this->getFirstLink('');
- $this->getLastLink('');
- $this->getPrevLink('');
- }
-
- function getNext (){
- return $this->display_link_next;
- }
-
- function getPrev(){
- return $this->display_link_prev;}
- return $this->display_link_prev;}
- (){
- return $this->display_link_first;
- }
-
- function getLast(){
- return $this->display_link_last;
- }
- return $this->display_link_last;
- }
-
($caption){- // 手機我們可以方法內容或備用電影電影內容
- if( $this->alt_content_count )
- $count = $this ->alt_content_count;
- else
- $count = $this->content_count;
-
- if( $this->display_offset $this->display_limit-$count >=0 ) {
-
- $this->display_link_next = $ this - >display_offset;
- }else{
- $this->display_link_next = min(
- $count-1,
- $this->display_offset $this->display_limit
- );
- }
- }
-
- return $this->buildLink( $this->buildNewURI( $this->display_link_next), $caption ) ;
- }
-
- function getPrevLink($caption){
-
- function getPrevLink($caption){
- $this - >display_link_prev = max(
- 0,
- $this->display_offset-$this->; display_limit
- );
- return $this->buildLink( $this->buildNewURI( $this->display_link_prev), $caption );
- }
-
- ftion getFirstLink($unction)
- $this->display_link_first = 0;
- return $this->buildLink( $this->buildNewURI( $this->display_link_first), $caption );
- }
- $this->display_link_last = $this->content_count-$this->display_limit;
- return $this->buildLink( $this->buildNewURI( $this->display_link_last), $標題);
- }
-
- ## NUMBERS
- function getPageCount(){
- if( $this->alt_content_count )
- $count = $this->alt_content_count; else
- $count = $this->content_count;
-
- $this->display_totalpages = ceil(
- $count / $this->display_limit
- );
- return $this- >display_totalpages;
- }
-
- function getPageNumbers(){
-
- //定義變數
- $midOffset = $this->display_mid_offset;
- $firstLink = $this-displaysplay_link_first;
- $firstLink = $this-display_link_first; = $this->getPageCount();
- $thisPage = $this->display_currentpage;
- $limit = $this->display_limit;
- $displayed=$midOffset*2 1;
- $returnAry =array();
-
- // 點
- $returnAry['afterdot'] = '';
- $returnAry['beforedot'] = '';
-
-
- // 如果兩次並居中,則數量小於所有頁面的總和
- if( ($midOffset*2 1) $min = max($firstLink ,$thisPage-$midOffset) ;
- $max = min($pageCount,$thisPage $midOffset 1);
- $total = $max-$min;
-
- // 這保留了x 數量即使
- //您不在第1 頁或第2 頁的中間也會顯示頁數
- if($total
- if($min==0){
- $max =$ displayed-$total;
- }
- if($max==$pageCount){
- $min-=$displayed-$total;
- }
- }
-
- } else{
- # 只輸出一組數字
- $min = 0;
- $max = $pageCount;
- }
-
- //運行頁面,檢查目前頁面並將其命名為
- for($i=$min;$i$cp = '否';
- if($thisPage==$i)
- $cp = '是';
-
- if($max!=$pageCount )
- $returnAry['afterdot'] = '...';
-
- if($min>0)
- $returnAry['beforedot'] = '...';
-
- array_push($returnAry,
- array(
- 'currentPage'=>$cp,
- 'pageNumber'= >($i 1),
- 'pageLink'=>; $this->buildLink( $this->buildNewURI( ($i*$limit) ), ($i 1) )
- )
- );
- }
-
- return $ returnAry;
-
- }
-
- function makePageNumbers($format, $pages,$boldCurrent=true,$,$se)
- $retPages = '';
-
- // 產生實際頁碼
- foreach($pages as $key => $value):
- if(is_numeric($key))
- $retPages .= ('yes'==$value ['currentPage'] && $boldCurrent)?''.$value['pageLink'] .''.$separator:$value[' pageLink'].$separator;
- endforeach;
-
- $format = str_replace( array('{beforedot}',
- '{afterdot}',
- '{pages}',
- '{afterdot}',
- '{pages}',
- '{separator}'),
- array( $pages['beforedot'],
- $pages['afterdot'],
- $retPages),
- $format);
- return $format;
- }
-
- ## 檢查
- 函數isFirstPage(){
- if($this->display_currentpage==0)
- 回傳true;
- 回傳false ;
- }
- 函數isLastPage(){
- // 加一,因為基數是0,而不是1
- if($this->display_currentpage 1==$this->getPageCount())
- return true;
- return false;
- }
-
- ## 函數
- function getPageName(){
- $fileName =explode('/',$_SERPVER['REQUEST_RIURIU ']);
- $fileName = $fileName[count($fileName)-1];
-
- if(strpos($fileName,'?')>0) {
- $fileName =explode ('?',$fileName) ;
- $fileName = $fileName[0];
- }
-
- return $fileName;
- }
-
- function getCleanURI(){
- $URI = $_SERVER ['REQUEST_URI'];
- if(strpos($URI,'?')>0){
- $URI =explode('?',$URI);
- $URI = $URI[ 1];
-
- $URI = preg_replace('/b'.$this->display_offset_var.'b[=0-9&]{2,20}/','' ,$URI);
- //$URI = preg_replace('/b'.$this->display_limit_var.'b[=0-9&]{2,20}/','',$URI);
-
- return $URI;
- }
- 回傳false;
- }
-
- function buildNewURI($offset){
- $newFile = $this->getPageName() this。 '? ' 。 $this->getCleanURI();
-
- $lastChar = substr($newFile,strlen($newFile)-1,1);
- if( $lastChar != '&' && $lastChar ! = '?' )
- $newFile.='&';
-
- $newFile .= $this->display_offset_var.'='.$offset.'&';
- //$ newFile . = $this->display_limit_var.'='.$limit.'&';
-
- return $newFile;
- }
-
- function buildLink( $href, $caption, $target= NULL ){
- if( $target != NULL )
- $target = ' target="'.$target.'"';
- return ''.$caption.'';
- }
-
- functionencodeURI($str){
- $salt = 'falaful ';
- $str = strrev($salt.$str);
- 回傳base64_encode($str);
- }
-
- 函數decodeURI($str){
- $salt = 'falaful';
- $str = strrev( base64_decode($str) );
- $str = substr( $str, strlen($salt), strlen($str) );return $str; }
-
- ##############
- #
- #這些函數用來輸入要執行的
- #類別的查詢。其他函數將取得所有
- #x 行,然後將其截斷。這些函數將
- #only 限制為任意數量。這提高了性能。
- #原因是當您需要 3 行時,您不會抓取 1,000,000 行。
- #
- ##############
-
- function runWQuery ($db, $statement, $table, $where=''){
-
- //取得總行數
- $db->query( 'SELECT COUNT(*) AS count FROM '. $表. $where );
- $db->movenext();
- $this ->alt_content_count = $db->col['count'];
-
- / / 新增限制查詢
- $where .= ' LIMIT ' 。 $this->display_offset .', '.$this->display_limit;
-
- // 儲存查詢
- $this->sql_query = $statement . ' 從 ' 。 $表。 ' '。 $where;
-
- // 列印查詢
- //echo $this->sql_query;
-
- // 執行查詢
- $db->query( $this-> ;sql_query );
- $this->sql_results = array();
-
- //儲存結果
- while($db->movenext()){
- array_push($this -> $db->col);
- }
-
- return $this->runQueryActions();
- }
-
- function runQueryActions(){
- $this->setContent( $this->sql_results );
-
- $pages = $this->getPageNumbers();
-
- // 產生實際頁碼
- $ retPages = $this->makePageNumbers( '{beforedots( '{beforedot } {pages} {afterdot}', $pages, true, ' ' );
-
- //取得新的顯示
- return array(
- 'content'=>$this->sql_results,
- 'pages'=>$retPages
- );
- }
- }
- ?>
複製代碼
|