Two Practical PHP paging code

Source: Internet
Author: User

function Outpege ($ps tutorial, $page)
{
$ps Cumulative number of information $page the current page number $max the maximum number of lists $min the minimum value of the list
$max = ($page >= 5)? $page +5:10;
if ($max > $ps) $max = $ps;
$min = ($page-5);
if ($min <1) $min = 1;
if ($page >1) $pagelist = "<a href="? page=1 "> Home </a>";
for ($i = $min; $i <= $max; $i + +) {
$pagelist. = ($i!= $page)? "<a href="? page={$i} ">{$i}</a>": "<a href=" # ">{$page}</a>";
}
$pagelist. = ($page >= $ps)? ': "<a href="? page={$ps} "> Last </a>";
return $pagelist;
}

Paging Code Two

Pagination, {Total number of records, per page display, current page, maximum number of pages displayed, page URL}

Function page ($toalrecord, $perpagenum, $curpage, $url) {
$total = Ceil ($toalrecord/$perpagenum);
$pagearr = Array_slice (range (1, $total), max (0, $curpage-~ ~ ($perpagenum/2)), $perpagenum);
if ($pagearr [0]!= 1) {
Array_unshift ($pagearr, sprintf ("<a href= ' {$url}%s ' ><<</a>", $pagearr [0]-1));
}
if ($pagearr [count ($pagearr)-1]!= $total) {
Array_push ($pagearr, sprintf ("<a href= ' {$url}%s ' >>></a>", $pagearr [Count ($pagearr)-1] + 1));
}
foreach ($pagearr as $i => & $v) {
$v = Is_numeric ($v)? "<a href= ' {$url} {$v} ' >{$v}</a>": $v;
}
Return "<a href= ' {$url} ' > Home </a>". Implode (", $pagearr). "<a href= ' {$url}". $total. "' > Last </a>";
}

Call

Page (99/* total record * * *, 9/* per page display number * * *, page/* current page, starting from 1 * * *, ' http://www.111cn.net/?page= '/*url prefix * *);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.