Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the paging function of php

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to achieve paging function in php". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to achieve the paging function of php"!

The copy code is as follows:

/ / paging function page 1: url/1 page 2: url/2

Function pages ($url, $totalnum, $page, $pagesize = 20) {

$urladd =''

Url. ='/'

$totalpage = ceil ($totalnum / $pagesize)

If ($totalpage

< 2) return ''; $page = min($totalpage, $page); $shownum = 5; // 显示多少个页 * 2 $start = max(1, $page - $shownum); $end = min($totalpage, $page + $shownum); // 不足 $shownum,补全左右两侧 $right = $page + $shownum - $totalpage; $right >

0 & & $start = max (1, $start-= $right)

$left = $page-$shownum

$left

< 0 && $end = min($totalpage, $end -= $left); $s = ''; $page != 1 && $s .= '◀'; if($start >

1) $s. ='1'. ($start > 2?'. ':).

For ($iTunes start; $I 1? '... ':). $totalpage.''

$page! = $totalpage & & $s. = '▶'

Return $s

}

Function mid ($n, $min, $max) {

If ($n

< $min) return $min; if($n >

$max) return $max

Return $n

}

Function page ($page, $n, $pagesize) {

$total = ceil ($n / $pagesize)

$total < 1 AND $total = 1

Return mid ($page, 1, $total)

}

We can take care of the back part in a few words.

The copy code is as follows:

$pagesize = 20; / / how many users are displayed per page

$n = user_count (); / / number of total users

$page = page ($page, $n, $pagesize); / / current pages

$userlist = user_find ($page, $pagesize); / / find out the user of the current page

/ / html part, paging effect, which can be directly rendered to the page.

$pagehtml = pages (url prefix, $n, $page, $pagesize)

At this point, I believe that everyone on the "php how to achieve paging function" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report