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

Table of Contents
PHP implements customizable style paging class, php custom style paging
Articles you may be interested in:
Home Backend Development PHP Tutorial PHP implements customizable style paging class, php custom style paging_PHP tutorial

PHP implements customizable style paging class, php custom style paging_PHP tutorial

Jul 12, 2016 am 08:55 AM
php

PHP implements customizable style paging class, php custom style paging

The example in this article shares with you PHP implements customizable style paging class for your reference. The specific content is as follows

<&#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>標簽 總體樣式 
 * @param string $PageUrl  當(dāng)前頁樣式
 * @param number $PageSize  每頁顯示的數(shù)據(jù)條數(shù)
 * @param number $ShowPage  每次顯示的頁數(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,不傳也可以打開上面的代碼自動獲取
 $this->PageUrl  = is_null ( $PageUrl ) &#63; $url : $PageUrl;
 }
 
 /**
 *
 * @param number $Page  
 * @param string $ShowToPage
 *  首頁,上下頁,尾頁
 * @param string $Html 標簽元素,li,p 
 * @return string
 */
 public function getPage($Page = 1, $ShowToPage = true, $Html = null) {
 $StartPage  = ($Page - $this->Floorp); // 開始頁碼
 $EndPage  = ($Page + $this->Floorp); // 結(jié)束頁碼
  
 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; 首頁</a>$Ehtml";
  $PrveUrl   = $this->getPrve($Page);
  $PageHtml  .= "$Shtml<a href='{$PrveUrl}'>&laquo; 上一頁</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}'>下一頁 &raquo;</a>$Ehtml";
  $PageHtml  .= "$Shtml<a href='{$this->PageUrl}p={$this->CountPage}' >尾頁 &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;
 }
 
 
 
}

Let me share with you another one that is mainly used for novices to learn PHP paging. The code is simple and practical, and the comments are complete.

1. Page.class.php

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

The above is the entire content of this article. I hope it will be helpful to everyone in learning PHP programming.

Articles you may be interested in:

  • php fairly simple paging class
  • PHP ajax paging class code
  • PHP paging class (imitating google)- Answers to interview questions
  • PHP paging code (simple and easy to use)
  • A PHP paging code
  • Exquisite and beautiful PHP paging code
  • A simple and easy-to-use PHP paging class
  • Detailed explanation of using ThinkPHP paging class
  • ThinkPHP usage experience sharing - Usage of paging class Page
  • Efficient mongodb PHP paging class ( Not using skip)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117070.htmlTechArticlePHP implements customizable style paging class, php custom style paging This article shares the example of PHP implementation that can be Custom style paging class for your reference, the specific content is as follows php...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

How does PHP handle Environment Variables? How does PHP handle Environment Variables? Jul 14, 2025 am 03:01 AM

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach

See all articles