国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

??
PHP實(shí)現(xiàn)可自定義樣式的分頁(yè)類,php自定義樣式分頁(yè)
您可能感興趣的文章:
? ??? ?? PHP ???? PHP實(shí)現(xiàn)可自定義樣式的分頁(yè)類,php自定義樣式分頁(yè)_PHP教程

PHP實(shí)現(xiàn)可自定義樣式的分頁(yè)類,php自定義樣式分頁(yè)_PHP教程

Jul 12, 2016 am 08:55 AM
php

PHP實(shí)現(xiàn)可自定義樣式的分頁(yè)類,php自定義樣式分頁(yè)

本文實(shí)例為大家分享了PHP實(shí)現(xiàn)可自定義樣式的分頁(yè)類,供大家參考,具體內(nèi)容如下

<&#63;php
 
//namespace Component;
/**
 * 2016-3-27
 * @author ankang
 */
class Page {
 private $ShowPage;
 private $CountPage;
 private $Floorp;
 private $PageUrl;
 private $PageClass;
 private $CurClass;
 
 /**
 * @author ankang
 * @param number $CountNum  數(shù)據(jù)總數(shù)
 * @param string $PageUrl  跳轉(zhuǎn)鏈接
 * @param string $PageClass  <a>標(biāo)簽 總體樣式 
 * @param string $PageUrl  當(dāng)前頁(yè)樣式
 * @param number $PageSize  每頁(yè)顯示的數(shù)據(jù)條數(shù)
 * @param number $ShowPage  每次顯示的頁(yè)數(shù) 
 */
 public function __construct($CountNum, $PageUrl = NULL, $PageClass = NULL,$CurClass = NULL, $PageSize = 20, $ShowPage = 5) {
 $this->ShowPage = $ShowPage;
 $this->CountPage  = ceil ( $CountNum / $PageSize );
 $this->Floorp  = floor ( $ShowPage / 2 ); // 偏移量 
 $this->PageClass  = is_null ( $PageClass ) &#63; '' : $PageClass;
 $this->CurClass = is_null ( $CurClass ) &#63; '' : $CurClass;
  
 // $ServerURL  = ( preg_match('/\&#63;/i', $_SERVER['REQUEST_URI']))&#63;preg_replace('/\&p\=[0-9]+/i', "", $_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI']."&#63;";
 // if( substr($ButURL,0,2)=='//' ){
  // $ServerURL  = substr($ServerURL,1);
 // }
 // $url   = preg_replace('/p=[\d]*/i', '', $ServerURL);
  $url   = '';
 //推薦自己傳url,不傳也可以打開(kāi)上面的代碼自動(dòng)獲取
 $this->PageUrl  = is_null ( $PageUrl ) &#63; $url : $PageUrl;
 }
 
 /**
 *
 * @param number $Page  
 * @param string $ShowToPage
 *  首頁(yè),上下頁(yè),尾頁(yè)
 * @param string $Html 標(biāo)簽元素,li,p 
 * @return string
 */
 public function getPage($Page = 1, $ShowToPage = true, $Html = null) {
 $StartPage  = ($Page - $this->Floorp); // 開(kāi)始頁(yè)碼
 $EndPage  = ($Page + $this->Floorp); // 結(jié)束頁(yè)碼
  
 if ($this->CountPage < $this->ShowPage) {
  $StartPage = 1;
  $EndPage = $this->CountPage;
 }
  
 if ($StartPage < 1) {
  $StartPage = 1;
  $EndPage = $this->ShowPage;
 }
  
 if ($EndPage > $this->CountPage) {
  $StartPage = $this->CountPage - $this->ShowPage + 1;
  $EndPage = $this->CountPage;
 }
  
 $PageHtml = '';
  
 if (! is_null ( $Html )) {
  if ($Html == 'li') {
  $Shtml = '<li>';
  $Ehtml = '</li>';
  } else {
  $Shtml = '<p>';
  $Ehtml = '</p>';
  }
 }
  
 if (true == $ShowToPage) {
  $PageHtml  .= "$Shtml<a href='{$this->PageUrl}p=1'>&laquo; 首頁(yè)</a>$Ehtml";
  $PrveUrl   = $this->getPrve($Page);
  $PageHtml  .= "$Shtml<a href='{$PrveUrl}'>&laquo; 上一頁(yè)</a>$Ehtml";
 }
  
 for($i = $StartPage; $i <= $EndPage; $i ++) {
  if ($Page == $i) {
  $PageHtml  .= "$Shtml<a href='{$this->PageUrl}p={$i}' class='{$this->CurClass}'>{$i}</a>$Ehtml";
  } else {
  $PageHtml  .= "$Shtml<a href='{$this->PageUrl}p={$i}' class='{$this->PageClass}'>{$i}</a>$Ehtml";
  }
 }
  
 if (true == $ShowToPage) {
  $NextUrl   = $this->getNext($Page);
  $PageHtml  .= "$Shtml<a href='{$NextUrl}'>下一頁(yè) &raquo;</a>$Ehtml";
  $PageHtml  .= "$Shtml<a href='{$this->PageUrl}p={$this->CountPage}' >尾頁(yè) &raquo;</a>$Ehtml";
 }
  
 return $PageHtml;
 }
 
 public function getPrve($Page){
 if ($Page != 1) {
  $Prve  = $Page - 1;
  $PrveUrl  = "{$this->PageUrl}p={$Prve}";
 } else {
  $PrveUrl  = "{$this->PageUrl}p=1";
 }
  
 return $PrveUrl;
 }
 
 public function getNext($Page){
 if ($Page != $this->CountPage) {
  $Next  = $Page + 1;
  $NextUrl  = "{$this->PageUrl}p={$Next}";
 } else {
  $NextUrl  = "{$this->PageUrl}p={$this->CountPage}";
 }
  
 return $NextUrl;
 }
 
 
 
}

再為大家分享一個(gè)主要用于新手學(xué)習(xí)php分頁(yè),代碼簡(jiǎn)單實(shí)用,主要是注釋很完整。

1. Page.class.php

<&#63;php
/**
 * 分頁(yè)類
 * 
 * 調(diào)用方式:
 * $p=new Page(總頁(yè)數(shù),顯示頁(yè)數(shù),當(dāng)前頁(yè)碼,每頁(yè)顯示條數(shù),[鏈接]);
 * print_r($p->getPages()); //生成一個(gè)頁(yè)碼數(shù)組(鍵為頁(yè)碼,值為鏈接)
 * echo $p->showPages(1); //生成一個(gè)頁(yè)碼樣式(可添加自定義樣式)
 * 
 * @author: Dzer <Email:358654744@qq.com Blog:Dzer.me>
 * @version: 2014-12-25 09:09:42
 * @Last Modified time: 2014-12-28 17:37:13
 */
 
/*
思路:
給我一個(gè) 總頁(yè)數(shù),需要顯示的頁(yè)數(shù),當(dāng)前頁(yè),每頁(yè)顯示的條數(shù),連接
寫一個(gè)方法 生成一個(gè)一維數(shù)組,鍵為頁(yè)碼 值為連接
寫一個(gè)方法 返回一個(gè)生成好樣式的頁(yè)碼(并且可以根據(jù)自己需要添加樣式)
默認(rèn)樣式 共45條記錄,每頁(yè)顯示10條,當(dāng)前第1/4頁(yè) [首頁(yè)] [上頁(yè)] [1] [2] [3] .. [下頁(yè)] [尾頁(yè)]
*/
class Page{
 protected $count;  //總條數(shù)
 protected $showPages; //需要顯示的頁(yè)數(shù)
 protected $countPages; //總頁(yè)數(shù)
 protected $currPage; //當(dāng)前頁(yè)
 protected $subPages; //每頁(yè)顯示條數(shù)
 protected $href;  //連接
 protected $page_arr=array(); //保存生成的頁(yè)碼 鍵頁(yè)碼 值為連接
 
 /**
  * __construct 構(gòu)造函數(shù)(獲取分頁(yè)所需參數(shù))
  * @param int $count  總條數(shù)
  * @param int $showPages 顯示頁(yè)數(shù)
  * @param int $currPage 當(dāng)前頁(yè)數(shù)
  * @param int $subPages 每頁(yè)顯示數(shù)量
  * @param string $href 連接(不設(shè)置則獲取當(dāng)前URL)
  */
 public function __construct($count,$showPages,$currPage,$subPages,$href=''){
  $this->count=$count;
  $this->showPages=$showPages;
  $this->currPage=$currPage;
  $this->subPages=$subPages;
   
  //如果鏈接沒(méi)有設(shè)置則獲取當(dāng)前連接
  if(empty($href)){
   $this->href=htmlentities($_SERVER['PHP_SELF']); 
  }else{
   $this->href=$href;
  }
  $this->construct_Pages();
 }
 
 /**
  * getPages 返回頁(yè)碼數(shù)組
  * @return array 一維數(shù)組 鍵為頁(yè)碼 值為鏈接
  */
 public function getPages(){
  return $this->page_arr;
 }
 
 /**
  * showPages 返回生成好的頁(yè)碼
  * @param int $style 樣式
  * @return string  生成好的頁(yè)碼
  */
 public function showPages($style=1){
  $func='pageStyle'.$style;
  return $this->$func();
 }
 
 /**
  * pageStyle1 分頁(yè)樣式(可參照這個(gè)添加自定義樣式 例如pageStyle2())
  * 樣式 共45條記錄,每頁(yè)顯示10條,當(dāng)前第1/4頁(yè) [首頁(yè)] [上頁(yè)] [1] [2] [3] .. [下頁(yè)] [尾頁(yè)] 
  * @return string 
  */
 protected function pageStyle1(){
  /* 構(gòu)造普通模式的分頁(yè) 
  共4523條記錄,每頁(yè)顯示10條,當(dāng)前第1/453頁(yè) [首頁(yè)] [上頁(yè)] [1] [2] [3] .. [下頁(yè)] [尾頁(yè)] 
  */
  $pageStr='共'.$this->count.'條記錄,每頁(yè)顯示'.$this->subPages.'條';
  $pageStr.='當(dāng)前第'.$this->currPage.'/'.$this->countPages.'頁(yè) ';
 
  $_GET['page'] = 1;
  $pageStr.='<span>[<a href="'.$this->href.'&#63;'.http_build_query($_GET).'">首頁(yè)</a>] </span>';
  //如果當(dāng)前頁(yè)不是第一頁(yè)就顯示上頁(yè)
  if($this->currPage>1){
   $_GET['page'] = $this->currPage-1;
   $pageStr.='<span>[<a href="'.$this->href.'&#63;'.http_build_query($_GET).'">上頁(yè)</a>] </span>';
  }
 
  foreach ($this->page_arr as $k => $v) {
   $_GET['page'] = $k;
   $pageStr.='<span>[<a href="'.$v.'">'.$k.'</a>] </span>';
  }
 
  //如果當(dāng)前頁(yè)小于總頁(yè)數(shù)就顯示下一頁(yè)
  if($this->currPage<$this->countPages){
   $_GET['page'] = $this->currPage+1;
   $pageStr.='<span>[<a href="'.$this->href.'&#63;'.http_build_query($_GET).'">下頁(yè)</a>] </span>';
  }
 
  $_GET['page'] = $this->countPages;
  $pageStr.='<span>[<a href="'.$this->href.'&#63;'.http_build_query($_GET).'">尾頁(yè)</a>] </span>';
 
  return $pageStr;
 }
 
 /**
  * construct_Pages 生成頁(yè)碼數(shù)組
  * 鍵為頁(yè)碼,值為鏈接
  * $this->page_arr=Array(
  *     [1] => index.php&#63;page=1
  *     [2] => index.php&#63;page=2
  *     [3] => index.php&#63;page=3
  *     ......)
  */
 protected function construct_Pages(){
  //計(jì)算總頁(yè)數(shù)
  $this->countPages=ceil($this->count/$this->subPages);
  //根據(jù)當(dāng)前頁(yè)計(jì)算前后頁(yè)數(shù)
  $leftPage_num=floor($this->showPages/2);
  $rightPage_num=$this->showPages-$leftPage_num;
 
  //左邊顯示數(shù)為當(dāng)前頁(yè)減左邊該顯示的數(shù) 例如總顯示7頁(yè) 當(dāng)前頁(yè)是5 左邊最小為5-3 右邊為5+3
  $left=$this->currPage-$leftPage_num;
  $left=max($left,1); //左邊最小不能小于1
  $right=$left+$this->showPages-1; //左邊加顯示頁(yè)數(shù)減1就是右邊顯示數(shù)
  $right=min($right,$this->countPages); //右邊最大不能大于總頁(yè)數(shù)
  $left=max($right-$this->showPages+1,1); //確定右邊再計(jì)算左邊,必須二次計(jì)算
   
  for ($i=$left; $i <= $right; $i++) {
   $_GET['page'] = $i;
   $this->page_arr[$i]=$this->href.'&#63;'.http_build_query($_GET);
  }
 }
}

2. demo.php

<&#63;php
/**
 * 分頁(yè)類demo
 * Be the best of whatever you are!
 * 
 * @author: Dzer<358654744@qq.com>
 * @version: 2014-12-28 17:38:23
 * @Last Modified time: 2014-12-28 18:08:28
 */
header("content-type:text/html;charset=utf8");
include('./Page.class.php'); //引入類
 
//$p=new Page(總頁(yè)數(shù),顯示頁(yè)數(shù),當(dāng)前頁(yè)碼,每頁(yè)顯示條數(shù),[鏈接]);
//連接不設(shè)置則為當(dāng)前鏈接
$page=isset($_GET['page']) &#63; $_GET['page'] : 1;
$p=new Page(100,7,$page,8);
 
//生成一個(gè)頁(yè)碼數(shù)組(鍵為頁(yè)碼,值為鏈接)
echo "<pre class="brush:php;toolbar:false">";
print_r($p->getPages()); 
 
//生成一個(gè)頁(yè)碼樣式(可添加自定義樣式)
//樣式 共45條記錄,每頁(yè)顯示10條,當(dāng)前第1/4頁(yè) [首頁(yè)] [上頁(yè)] [1] [2] [3] .. [下頁(yè)] [尾頁(yè)]
echo $p->showPages(1); 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:

  • php相當(dāng)簡(jiǎn)單的分頁(yè)類
  • PHP ajax 分頁(yè)類代碼
  • PHP 分頁(yè)類(模仿google)-面試題目解答
  • PHP 分頁(yè)類代碼(簡(jiǎn)單好用型)
  • 一個(gè)PHP分頁(yè)類的代碼
  • 精美漂亮的php分頁(yè)類代碼
  • 一個(gè)簡(jiǎn)單且很好用的php分頁(yè)類
  • ThinkPHP分頁(yè)類使用詳解
  • ThinkPHP使用心得分享-分頁(yè)類Page的用法
  • 高效mongodb的php分頁(yè)類(不使用skip)

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1117070.htmlTechArticlePHP實(shí)現(xiàn)可自定義樣式的分頁(yè)類,php自定義樣式分頁(yè) 本文實(shí)例為大家分享了PHP實(shí)現(xiàn)可自定義樣式的分頁(yè)類,供大家參考,具體內(nèi)容如下 php...
? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
PHP? AI ??? ?? ?? PHP ?? ?? ?? ??? ??? ?????. PHP? AI ??? ?? ?? PHP ?? ?? ?? ??? ??? ?????. Jul 25, 2025 pm 08:45 PM

??? ?? ??? ??? ?? JavaScript? MediareCorder API? ?? PHP ???? ???? ?????. 2. PHP? ???? ?? ??? ???? STTAPI (? : Google ?? Baidu ?? ??)? ???? ???? ?????. 3. PHP? ???? AI ??? (? : OpenAigpt)? ????. 4. ?? ?? PHP? TTSAPI (? : Baidu ?? Google ?? ??)? ???? ??? ?? ??? ?????. 5. PHP? ?? ??? ??? ??? ??? ?? ?? ??? ?????. ?? ????? PHP? ?? ???? ?? ?? ?? ??? ??? ?????.

PHP? ???? ?? ?? ??? ???? ?? PHP ?? ????? ?? ?? PHP? ???? ?? ?? ??? ???? ?? PHP ?? ????? ?? ?? Jul 25, 2025 pm 08:51 PM

PHP?? ?? ?? ??? ???? ?? ??? ? ???? ?? ??? ???? ?? ??? ???? ???? ????. 1. ?? ?? ??? ?? ??? URL ? ?? ??? ????. 2. UrlenCode? ???? ?? ??? ???????. 3. ? ???? ????? ?? ?? ??? ? ?? ??? ?????. 4. ???? ???? ?? ? ? ??? ??? ??? ??? ?????. 5. ??? ?? ??? ????? ?? ????? OG ??? ???? ?????. 6. XSS ??? ???? ?? ??? ??? ?????. ? ???? ??? ??? ???? ??? ?? ?? ??? ??? ???? ??? ?? ??? ?????.

PHP? ???? AI? ???? ??? ?? ?? PHP ?? ?? ? ???? ?????. PHP? ???? AI? ???? ??? ?? ?? PHP ?? ?? ? ???? ?????. Jul 25, 2025 pm 08:57 PM

AI? ??? ??? ?? ?? ? ?? ???? ????? ?? ??? ??????. 1. Baidu, Tencent API ?? ?? ?? NLP ?????? ?? ??? AI ?? ?? API? ??????. 2. PHP? ? ?? guzzle? ?? API? ???? ?? ??? ??????. 3. ?? ????? ?? ?? ??? ???? ???? ???? ??? ??? ? ????. 4. ?? ?? ? ?? ???? ?? PHP-L ? PHP_CODESNIFFER? ??????. 5. ???? ????? ???? ?? ?? ??? ?????? ??? ??????. AIAPI? ??? ? ???, ?? ??, ?? ? PHP ?? ??? ??? ???. ?? ???? PSR ??? ???, ??? ????? ????, ?? ??? ???, ????? ??? ????, X? ???????.

PHP? PHP ?? ?? ? ?? ??? ??? ?????? ??? ??? ???? ????. PHP? PHP ?? ?? ? ?? ??? ??? ?????? ??? ??? ???? ????. Jul 25, 2025 pm 08:27 PM

1. ?? ???? ??? ??? ?????? ?? ?? ??? ??, ??? ?? ???? ??? (? : ?? ???, ? ? ??), ?? ??? ?? ???? ???? ? ?? ?? ??? ??? ?? ??? ????????. 2. ?? ??? ??? ?? ? ??? ???? ?? ?? ?? ???? ?? ? ?? AUDIT ?? ??? ??? ? ????? ????? ??? ???????. 3. ?? ?? ??? ?? ??? ???????. Recaptchav3 ???? ??, ??? ?? ?? ?? ?? ??, IP ? ?? ??? ??? ??? ?? ???? ??? ?? ??? ????? ??? ???? ????? ??? ?????.

PHP? ???? AI? ???? ???? ???? ??. PHP? ???? ?? ??? ????? PHP? ???? AI? ???? ???? ???? ??. PHP? ???? ?? ??? ????? Jul 25, 2025 pm 07:21 PM

PHP? AI ??? ??? ?? ????? ??? API? ?? ?????. ??? ??? ????? ? ??? ???? ?????. API ??? ?? ?? ??? ???? ??? ??? ???? ???? ? ????. 2. ?? ?? ???? guzzle ?? curl? ???? HTTP ??? ???, JSON ??? ??? ? ???, API ? ?? ??, ??? ? ?? ??? ???? ??, ??? ?? ?? ? ? ?? ????, ??? ?? ? ?????? ?????. 3. ???? ???? ?? ???? API ??, ?? ? ??? ?? ??, ??? ?? ??, ?? ?? ? ??? ??? ??? ?????. ?? ??? ??? ??? ? ??? ???? Propt ?? ? ?? ?? ??, ??? ?? ? ?? ????, ?? ?? ?? ???? ? ??? ?? ? ???? ????? ?????.

PHP? ?? ?? ?? ? ?? ?? PHP ?? ??? ? ?? ????? ?? PHP? ?? ?? ?? ? ?? ?? PHP ?? ??? ? ?? ????? ?? Jul 25, 2025 pm 08:30 PM

PHP? ?????? ????? ?? ?? ?? ???? ???? ?? ???? ???? ?? ?? ???? ?????. 2. ?? ??? ???? ???? ?? ??? ?? ? ??? ??? ???? ?? API/Webhook ??? ??? ?? ???? ??? ??? ??? ??? ?????. 3. ?? ????? ?? ??, ??/???? ????, ???? ??, ???? ? ??? ?????? ????? ?? ??? ???? ???? ?? Dingtalk, SMS ?? ??? ???? ??? ?????? ???? ?? ? ??? ??? ????? ?? ??? ???? ???????.

?? ?? ?? : ?? ?? ?????? PHP? ?? ?? ?? ?? : ?? ?? ?????? PHP? ?? Jul 27, 2025 am 04:31 AM

PhpisstillRelevantinmodernenterpriseenvironments.1. Modernphp (7.xand8.x)? ??? ??, ??? ??, jitcompilation ? modernsyntax, mateitsuilableforlarge-scalepplications

PHP ?? AI ?? ?? ? ??? PHP ?? ??? ?? ?? ??? PHP ?? AI ?? ?? ? ??? PHP ?? ??? ?? ?? ??? Jul 25, 2025 pm 07:06 PM

??? AI ?? ?? ???? ???? PHPSDK? ??????. 2. PHP? ???? FFMPEG? ???? ???? API ?? ?? (? : WAV)?? ?????. 3. ??? ???? ????? ????? API ???? ??? ??????. 4. NLP ??? ???? JSON ??? ???? ???? ?????. 5. ?? ??? ???? ???? ?? ?? ?? ?? ?? ??? ?????. ?? ????? ?? ?? ? ??? ???? ?? ??? ???, ??? ?? ? ??? ???????.

See all articles