Home php教程 php手册 简单实用的php分页函数代码

简单实用的php分页函数代码

Jun 06, 2016 pm 07:52 PM
linux php code function Pagination use Simple Enter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 一个简单实用的php分页函数,分页导航中可以默认为空,在函数内部再设置本页URL. 代码: ?php /** * 分页 * @category 功能 * @param $totle:信息总数 * @param $displaypg:每页显示信息数,这里设置

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  一个简单实用的php分页函数,分页导航中可以默认为空,在函数内部再设置本页URL.

  代码:

  

  /**

  * 分页

  * @category 功能

  * @param $totle:信息总数

  * @param $displaypg:每页显示信息数,这里设置为默认是20;

  * @param $url:分页导航中的链接,除了加入不同的查询信息"page"外的部分都与这个URL相同。默认值本该设为本页URL(即$_SERVER["REQUEST_URI"]),但设置默认值的右边只能为常量,所以该默认值设为空字符串,在函数内部再设置为本页URL.

  * @return string

  */

  function pageft($totle, $displaypg=20, $url=''){

  $page=fget("page", 1);

  $url=empty($url) ? $_SERVER["REQUEST_URI"] : $url;

  //URL分析:

  $parse_url=parse_url($url);

  $url_query=isset($parse_url["query"]) ? $parse_url["query"] : ""; //单独取出URL的查询字串

  if($url_query){

  $url_query=preg_replace("/page=[^&]*[&]?/i","",$url_query);

  $url=str_replace($parse_url["query"],$url_query,$url);//将处理后的URL的查询字串替换原来的URL的查询字串

  $url.="&page";//在URL后加page查询信息,但待赋值

  }else{

  $url.="?page";

  }

  //页码计算:

  $lastpg=ceil($totle/$displaypg); //最后页,也是总页数

  $lastpg=$lastpg ? $lastpg : 1; //没有显示条目,置最后页为1

  $page=min($lastpg,$page);

  $firstcount=($page-1)*$displaypg;

  //如果只有一页则跳出函数,没有分页的文字显示(备用)

  //if($lastpg

  //开始分页导航条代码

  $pagenav="显示第 ".($totle?($firstcount+1):0) . "/" . min($firstcount+$displaypg,$totle)。" 条记录,共 $totle 条记录
";

  $pagenav.=" 首页 ";

  if($prepg) $pagenav.=" 前页 "; else $pagenav.=" 前页 ";

  if($nextpg) $pagenav.=" 后页 "; else $pagenav.=" 后页 ";

  $pagenav.=" 尾页 ";

  //下拉跳转列表,循环列出所有页码

  $pagenav.=" 到第

  for($i=1;$i

  if($i==$page){

  $pagenav.="\n";

  }else{

  $pagenav.="\n";

  }

  }

  $pagenav.=" 页,共 $lastpg 页";

  //组织返回值

  $re_str['limit'] = "limit {$firstcount},{$displaypg}";

  $re_str['str'] = $pagenav;

  return $re_str;

  }

简单实用的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

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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Apr 06, 2025 am 12:07 AM

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

How can you prevent a class from being extended or a method from being overridden in PHP? (final keyword) How can you prevent a class from being extended or a method from being overridden in PHP? (final keyword) Apr 08, 2025 am 12:03 AM

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

C language conditional compilation: a detailed guide for beginners to practical applications C language conditional compilation: a detailed guide for beginners to practical applications Apr 04, 2025 am 10:48 AM

C language conditional compilation is a mechanism for selectively compiling code blocks based on compile-time conditions. The introductory methods include: using #if and #else directives to select code blocks based on conditions. Commonly used conditional expressions include STDC, _WIN32 and linux. Practical case: Print different messages according to the operating system. Use different data types according to the number of digits of the system. Different header files are supported according to the compiler. Conditional compilation enhances the portability and flexibility of the code, making it adaptable to compiler, operating system, and CPU architecture changes.

libv are two libv are two Apr 03, 2025 pm 08:03 PM

I developed a project called Lua-Libuv and am happy to share my experience. The original intention of the project is to explore how to use Libuv (an asynchronous I/O library written in C) to build a simple HTTP server without having to learn the C language in depth. With the help of ChatGPT, I completed the basic code of HTTP.C. When dealing with persistent connections, I successfully implemented closing the connection and freeing resources at the right time. At first I tried to create a simple server that ended the main program by closing the connection, but I had some problems. I've tried sending blocks of data using streaming, and while it works, this blocks the main thread. In the end, I decided to give up on this approach because my goal was not to learn C language in depth. Finally, I

See all articles