search
Homephp教程php手册又一款php分页类代码

以前写过很多php 分页类但是今天这款分页程序我感觉是很好的,简洁实用,代码合理并没有多余的代码,是一款不错分页类函数哦。
 代码如下 复制代码

class multipage {

 var $total;
 var $perpage;
 var $pages;
 var $maxpage;
 var $offset = 9;
 var $curr_page;
 
 function init($total, $perpage, $maxpage) { //初始化页数
  $this->total;
  $this->perpage;
  $this->maxpage;
  $this->offset = 9;
 }
 
 function getpagelist() {//获取分页列表
  $result_pages = "";
  $this->pages = ceil($this->total / $this->perpage);
  
  if ($this->pages > $this->maxpage) {
   $from = $this->curr_page - $this->offset;
   if ($from     $from = 1;
   }
   $to = $from + $this->maxpage - 1;
   if ($to > $this->pages) {
    $to = $this->pages;
    if (($to - $from) maxpage) {
     $from = $from - 1;
    }
   }
  } else {
   $from = 1;
   $to = $this->pages;
  }
  
  $p = 0;
  for($i = $from; $i    $result_pages[$p] = $i;
   $p++;
  }
  
  return $result_pages;
 }
 
 function getfirst() { //获取第一页
  if ($this->curr_page > 1 && $this->pages > 1) {
   return 1;
  } else {
   return "";
  }
 }
 
 function getlast() { //取末页
  if ($this->pages > 1 && $this->curr_page pages) {
   return $this->pages;
  } else {
   return "";
  }
 }
 
 function getprev() {//上一页
  $prevpage = $this->curr_page - 1;
  if ($prevpage > 0) {
   return $prevpage;
  } else {
   $prevpage = "";
   return $prevpage;
  }
 }
 
 function getnext() {//下一页
  $nextpage = $this->curr_page + 1;
  if ($nextpage pages) {
   return $nextpage;
  } else {
   $nextpage = "";
   return $nextpage;
  }
 }
 
 function gettotal() {//共多少页
  if ($this->pages > 0) {
   return $this->pages;
  } else {
   return 1;
  }
 }
 
}

//分页类的使用方法

$page = new multipage();
$page->gettotal(); //总页娄
$page->getnext();//下一页

 



本文地址:

转载随意,但请附上文章地址:-)

Statement
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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor