PHP dynamic paging function, a must-have for PHP paging development

WBOY
Release: 2016-07-29 08:47:13
Original
1172 people have browsed it

Paste code:

Copy code The code is as follows:


/**
* Paging function
*
* @param int $count The total number of entries
* @param int $perlogs The number of entries displayed on each page
* @param int $page The current page number
* @param string $url The address of the page number
*/
function pagination($count,$perlogs,$page,$url,$anchor=''){
$ pnums = @ceil($count / $perlogs);
$re = '';
$urlHome = preg_replace("|[?&/][^./?&=]*page[=/-]|", "",$url);
for ($i = $page-5;$i <= $page+5 && $i <= $pnums; $i++){
if ($i > 0){
if ($i == $page){
$re .= " $i ";
} elseif($i == 1) {
$re .= " $i ";
} else {
$re .= " $i ";
}
}
}
if ($page > 6) $re = "«. ..$re";
if ($page + 5 < $pnums) $re .= "... »";
if ($pnums <= 1) $re = '';
return $re;
}

The above has introduced the PHP dynamic paging function, which is necessary for PHP development of paging. It includes various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!