Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the paging function of php

Shulou Source: shulou.com Published: 2022-06-03 15:47:12 09月27日 Update

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!

Tags: Code function user content part Learning practical deeper interest function prefix practicality practice simple Operation effect method more Friends number of users website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple Shulou Technology Shulou Tech Info OPPO Reno