suchen
Heimphp教程php手册PHP分页类的具体使用方法
PHP分页类的具体使用方法Jun 13, 2016 am 11:09 AM
php代码使用方法spezifisch分页existierenunsArtikelvon详细

我们在这篇文章中为大家详细介绍了有关

PHP分页类的代码示例:

  1.  ?php  
  2. //为了避免重复包含文件而造成错误,
    加了判断函数是否存在的条件:  
  3. if(!function_exists(pageft)){   
  4. //定义函数pageft(),三个参数的含义为:  
  5. //$totle:信息总数;  
  6. //$displaypg:每页显示信息数,这里设置为默认是20;  
  7. //$url:分页导航中的链接,除了加入不同的
    查询信息“page”外的部分都与这个URL相同。  
  8. //默认值本该设为本页URL(即$_SERVER
    ["REQUEST_URI"]),但设置默认值的右边
    只能为常量,所以该默认值设为空字符串,在函数内部再设置为本页URL。  
  9. function pageft($totle,$displaypg=20,$url=''){  
  10. //定义几个全局变量:   
  11. //$page:当前页码;  
  12. //$firstcount:(数据库)查询的起始项;  
  13. //$pagenav:页面导航条代码,函数内部并没有将它输出;  
  14. //$_SERVER:读取本页URL“$_SERVER["REQUEST_URI"]”所必须。  
  15. global $page,$firstcount,$pagenav,$_SERVER;  
  16. //为使函数外部可以访问这里的“$displaypg”
    ,将它也设为全局变量。注意一个变量重新定义
    为全局变量后,原值被覆盖,所以这里给它重新赋值。  
  17. $GLOBALS["displaypg"]=$displaypg;  
  18. if(!$page) $page=1;  
  19. //如果$url使用默认,即空值,则赋值为本页URL:  
  20. if(!$url){ $url=$_SERVER["REQUEST_URI"];}  
  21. //URL分析:  
  22. $parse_urlparse_url=parse_url($url);  
  23. $url_query=$parse_url["query"]; //单独取出URL的查询字串  
  24. if($url_query){  
  25. //因为URL中可能包含了页码信息,
    我们要把它去掉,以便加入新的页码信息。  
  26. //这里用到了正则表达式  
  27. $url_query=ereg_replace("(^|&)page=$page","",$url_query);  
  28. //将处理后的URL的查询字串替换原来的URL的查询字串:  
  29. $url=str_replace($parse_url["query"],$url_query,$url);  
  30. //在URL后加page查询信息,但待赋值:   
  31. if($url_query) $url.="&page"; else $url.="page";  
  32. }else {  
  33. $url.="?page";  
  34. }  
  35. //页码计算:  
  36. $lastpg=ceil($totle/$displaypg); //最后页,也是总页数  
  37. $page=min($lastpg,$page);  
  38. $prepg=$page-1; //上一页  
  39. $nextpg=($page==$lastpg ? 0 : $page+1); //下一页  
  40. $firstcount=($page-1)*$displaypg;  
  41. //开始分页导航条代码:  
  42. $pagenav="显示第 ".($totle?($firstcount+1):0)."
    B>-B>".min($firstcount+$displaypg,$totle)."
    B> 条记录,共 $totle 条记录BR>";  
  43. //如果只有一页则跳出函数:  
  44. if($lastpg=1) return false;  
  45. $pagenav.=" 首页 ";  
  46. if($prepg) $pagenav.="  $url=$prepg'>前页 "; else $pagenav.=" 前页 ";  
  47. if($nextpg) $pagenav.=
    后页 "
    ; else $pagenav.=" 后页 ";  
  48. $pagenav.=" 尾页 ";  
  49. //下拉跳转列表,循环列出所有页码:  
  50. $pagenav.=" 到第   size='1' onchange='window.location="$url="+this.value'>n";  
  51. for($i=1;$i=$lastpg;$i++){  
  52. if($i==$page) $pagenav.=" option value='$i' selected>$in";  
  53. else $pagenav.=";  
  54. }  
  55. $pagenav.=" 页,共 $lastpg 页";  
  56. }  
  57. }  
  58. ?> 

以上就是PHP分页类的详细使用方式,希望对大家有所帮助。


Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heiße Werkzeuge

SublimeText3 Linux neue Version

SublimeText3 Linux neue Version

SublimeText3 Linux neueste Version

Herunterladen der Mac-Version des Atom-Editors

Herunterladen der Mac-Version des Atom-Editors

Der beliebteste Open-Source-Editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

VSCode Windows 64-Bit-Download

VSCode Windows 64-Bit-Download

Ein kostenloser und leistungsstarker IDE-Editor von Microsoft