Several different styles PHP paging code (1/8)

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;
}

Method Two

/**
* Show Paging function
* Records Total records, currentpage current pages, rows per page record number, listpage page number list length.
*/
function ShowPage ($records, $currentpage, $rows =20, $listpages =7) {
if ($records <1) return ";
if ($rows <1) $rows = 20;
if ($listpages <3) $listpages = 7;
$action =$_server[' query_string ']; Get the Address bar? After the content
if ($action) {//Will page= ... Removed from the content
$action =preg_replace ("/&page[^&]*/", "", $action);
$action =preg_replace ("/page[^&]*&*/", "", $action);
}
if ($action) $action. = ' & ';
$maxpage =ceil ($records/$rows); The maximum number of pages can be obtained by rounding.
$middlepage =floor ($listpages/2); The rounding method takes half of the number of pages to be displayed.
if ($currentpage <1| | $currentpage > $maxpage) $currentpage = 1;
$startpage = $currentpage-$middlepage;
if ($maxpage-$currentpage <= $middlepage) $startpage = $maxpage-$listpages;
if ($startpage <2) $startpage = 2; Start Page calculation complete
$endpage = $startpage + $listpages;
if ($endpage > $maxpage) $endpage = $maxpage; End Page Calculation complete
if ($currentpage!=1) {
$pagestr = "<a href="? {$action}page=1 ' ><span>1</span></a> ';
}else{
$pagestr = "<span>1</span>";
}

Home 1 2 3 4 5 6 7 8 last

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.