search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Table of Contents
A complete example of php custom paging class,
Articles you may be interested in:
Home Backend Development PHP Tutorial Complete example of php custom paging class, _PHP tutorial

Complete example of php custom paging class, _PHP tutorial

Jul 12, 2016 am 09:02 AM
php

A complete example of php custom paging class,

The example in this article describes the php custom paging class. Share it with everyone for your reference, the details are as follows:

<?php
header("Content-type:text/html;Charset=utf-8");
class SubPages{
 private $each_disNums;//每页显示的条目数
 private $nums;//总条目数
 private $current_page;//当前被选中的页
 private $sub_pages;//每次显示的页数
 private $pageNums;//总页数
 private $page_array = array();//用来构造分页的数组
 private $subPage_link;//每个分页的链接
 //private $subPage_type;//显示分页的类型
/*
  当@subPage_type=1的时候为普通分页模式
     example:  共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页]
     当@subPage_type=2的时候为经典分页样式
     example:  当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
 */
 function __construct($each_disNums,$nums,$current_page,$sub_pages,$subPage_link){
  $this->each_disNums=intval($each_disNums);
 $this->nums=intval($nums);
 if(!$current_page){
 $this->current_page=1;
 }else{
   $this->current_page=intval($current_page);
  }
 $this->sub_pages=intval($sub_pages);
  $this->pageNums=ceil($nums/$each_disNums);
  $this->subPage_link=$subPage_link;
  // $this->show_SubPages($subPage_type);
 }
  // show_SubPages函数用在构造函数里面。而且用来判断显示什么样子的分页
 /* function show_SubPages($subPage_type){
   if($subPage_type == 1){
   $this->subPageCss1();
   }else if ($subPage_type == 2){
   $this->subPageCss2();
   }
  }
*/
  //用来给建立分页的数组初始化的函数。
 function initArray(){
   for($i=0;$i<$this->sub_pages;$i++){
   $this->page_array[$i]=$i;
 }
   return $this->page_array;
  }
  /* construct_num_Page该函数使用来构造显示的条目
  即使:[1][2][3][4][5][6][7][8][9][10] */
 function construct_num_Page(){
  if($this->pageNums < $this->sub_pages){
   $current_array=array();
   for($i=0;$i<$this->pageNums;$i++){
    $current_array[$i]=$i+1;
   }
   }else{
   $current_array=$this->initArray();
   if($this->current_page <= 3){
    for($i=0;$i<count($current_array);$i++){
     $current_array[$i]=$i+1;
    }
   }else if ($this->current_page <= $this->pageNums && $this->current_page > $this->pageNums - $this->sub_pages + 1 ){
    for($i=0;$i<count($current_array);$i++){
     $current_array[$i]=($this->pageNums)-($this->sub_pages)+1+$i;
    }
   }else{
    for($i=0;$i<count($current_array);$i++){
     $current_array[$i]=$this->current_page-2+$i;
    }
   }
  }
  return $current_array;
  }
 /*
  构造普通模式的分页
  共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页]
  */
 function subPageCss1(){
  $subPageCss1Str="";
  $subPageCss1Str.="共".$this->nums."条记录,";
  $subPageCss1Str.="每页显示".$this->each_disNums."条,";
  $subPageCss1Str.="当前第".$this->current_page."/".$this->pageNums."页 ";
  if($this->current_page > 1){
   $firstPageUrl=$this->subPage_link."1";
   $prewPageUrl=$this->subPage_link.($this->current_page-1);
   $subPageCss1Str.="[<a href='$firstPageUrl'>首页</a>] ";
   $subPageCss1Str.="[<a href='$prewPageUrl'>上一页</a>] ";
  }else {
   $subPageCss1Str.="[首页] ";
   $subPageCss1Str.="[上一页] ";
  }
  if($this->current_page < $this->pageNums){
   $lastPageUrl=$this->subPage_link.$this->pageNums;
   $nextPageUrl=$this->subPage_link.($this->current_page+1);
   $subPageCss1Str.=" [<a href='$nextPageUrl'>下一页</a>] ";
   $subPageCss1Str.="[<a href='$lastPageUrl'>尾页</a>] ";
  }else {
   $subPageCss1Str.="[下一页] ";
   $subPageCss1Str.="[尾页]";
  }
  return $subPageCss1Str; //在此可以设置显示的CSS样式
  }
 /*
  构造经典模式的分页
  当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
  */
 function subPageCss2(){
  $subPageCss2Str="";
  $subPageCss2Str.="当前第".$this->current_page."/".$this->pageNums."页 ";
 if($this->current_page > 1){
   $firstPageUrl=$this->subPage_link."1";
   $prewPageUrl=$this->subPage_link.($this->current_page-1);
   $subPageCss2Str.="[<a href='$firstPageUrl'>首页</a>] ";
   $subPageCss2Str.="[<a href='$prewPageUrl'>上一页</a>] ";
  }else {
   $subPageCss2Str.="[首页] ";
   $subPageCss2Str.="[上一页] ";
  }
 $a=$this->construct_num_Page();
  for($i=0;$i<count($a);$i++){
   $s=$a[$i];
   if($s == $this->current_page ){
    $subPageCss2Str.="[<span style='color:red;font-weight:bold;'>".$s."</span>]";
   }else{
    $url=$this->subPage_link.$s;
    $subPageCss2Str.="[<a href='$url'>".$s."</a>]";
   }
  }
  if($this->current_page < $this->pageNums){
   $lastPageUrl=$this->subPage_link.$this->pageNums;
   $nextPageUrl=$this->subPage_link.($this->current_page+1);
   $subPageCss2Str.=" [<a href='$nextPageUrl'>下一页</a>] ";
   $subPageCss2Str.="[<a href='$lastPageUrl'>尾页</a>] ";
  }else {
   $subPageCss2Str.="[下一页] ";
   $subPageCss2Str.="[尾页] ";
  }
  return $subPageCss2Str;
  }
}
//使用如下
/*include('../mysql.php');
//每页显示的条数
 $page_size=3;
//总条目数
$sql=mysql_query("select * from `stu_info`");
$nums=mysql_num_rows($sql);
//每次显示的页数
 $sub_pages=10;
//得到当前是第几页
 if(!isset($_GET["p"])){
 $pageCurrent=1;
 }else{
  $pageCurrent=$_GET["p"];
 }
 $subPages=new SubPages($page_size,$nums,$pageCurrent,$sub_pages,"page.php?p=");
 $page=$subPages->subPageCss2();
 echo $page;//在此可以设置CSS样式
 $ss=mysql_query("select * from `stu_info` limit ".$page_size*($pageCurrent-1).",".$page_size);
 while($row=mysql_fetch_array($ss)){
 echo $row['stunum'].''.$row['stuname'].''.$row['clanum'].'<br>';
 }*/
?>

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Two versatile PHP paging classes
  • implementation method of PHP simple paging class
  • Collection of PHP paging classes
  • An example of thinkphp paging class modified to imitate dedecms drop-down paging style
  • Efficient mongodb php paging class (without skip)
  • ThinkPHP usage experience sharing - usage of paging class Page
  • Detailed explanation of using ThinkPHP paging class
  • Exquisite and beautiful PHP paging class code
  • PHP paging class code (simple and easy to use)
  • PHP ajax paging class code

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084534.htmlTechArticleA complete example of php custom paging class. This example describes the php custom paging class. Share it with everyone for your reference, the details are as follows: phpheader("Content-type:text/html;Charset=utf-8")...
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

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

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 install Redis cluster on Linux_Linux distributed cache deployment solution [Advanced] How to install Redis cluster on Linux_Linux distributed cache deployment solution [Advanced] Feb 08, 2026 pm 07:39 PM

The Redis6 cluster must be created with redis-cli--cluster. It requires a minimum of 3 masters and 3 slaves, a total of 6 nodes. The client port and the corresponding cluster bus port (10000) must be opened. Correct configuration but blocked ports is a common cause of failure.

How to dynamically set arbitrary depth value of nested array in PHP How to dynamically set arbitrary depth value of nested array in PHP Mar 04, 2026 am 11:15 AM

This article introduces a safe and efficient method to use key path arrays (such as ['key1', 'key2', 'key3']) to assign values ​​to the last nodes of multi-dimensional associative arrays, solve the problem of reference failure caused by value transfer, and take into account key existence verification.

How to import SQL files in mysql_mysql SQL file import method How to import SQL files in mysql_mysql SQL file import method Feb 09, 2026 pm 05:24 PM

The most common and reliable way to import SQL files into MySQL is the command line tool mysql, which supports cross-platform, high efficiency and stability, and is suitable for files of all sizes. It can also be executed in the client through the source command, or using graphical tools such as phpMyAdmin and MySQL Workbench.

PHP batch processing of color mode and resolution of pictures in PPT PHP batch processing of color mode and resolution of pictures in PPT Mar 02, 2026 am 10:18 AM

To read PPTX images with PHP, you need to decompress the ZIP package first, because the images are stored in the ppt/media/ directory; directly calling the image function will report an error; you must use ZipArchive to decompress, Imagick to process CMYK to RGB conversion and scaling, and update the rels and [Content_Types].xml files simultaneously.

Where can I see the PHP operator priority table_php official operator priority [Reference] Where can I see the PHP operator priority table_php official operator priority [Reference] Mar 02, 2026 am 11:45 AM

The official description of PHP operator precedence is located at https://www.php.net/manual/en/language.operators.precedence.php. You need to directly search for "operatorprecedence" or manually enter the URL to access; == and === have the same priority and belong to the same level; error-prone combinations include &&/|| and and/or, ?: and ??, new and []; complex expressions must be bracketed.

Number statistics in pyramid loop in PHP: correct counting method of total, odd and even numbers Number statistics in pyramid loop in PHP: correct counting method of total, odd and even numbers Mar 04, 2026 pm 01:30 PM

This article explains in detail how to accurately count the total number, odd number and even number of all generated numbers in the PHP pyramid printing loop, correct common logic errors (such as misuse of variables, confusion of counting objects), and provide runnable examples and key precautions.

How to deal with character sets after mysql upgrade_mysql encoding migration instructions How to deal with character sets after mysql upgrade_mysql encoding migration instructions Feb 09, 2026 pm 07:17 PM

After the MySQL 8.0 upgrade, the default character set becomes utf8mb4, but the old table character set remains unchanged; latin1/utf8 tables need to be manually migrated, and the source character set must be specified when exporting. ALTERTABLECONVERT will re-encode the data, and the connection layer must explicitly declare utf8mb4.

How to install ThinkPHP with composer_Steps to deploy TP framework using composer How to install ThinkPHP with composer_Steps to deploy TP framework using composer Feb 12, 2026 am 06:27 AM

The ThinkPHP stable version should be clearly specified, such as using composercreate-projecttopthink/thinktp6^6.3 to install the TP6.3LTS version to avoid pulling non-production-ready beta versions because dev-master has switched to the TP8 preview version.

Related articles