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

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

Jun 06, 2016 pm 07:52 PM
linuxphpcodefunctionPaginationuseSimpleEnter

欢迎进入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
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

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.