PHP paging computing

Source: Internet
Author: User
PHP paging computing
$ Maxpage; // Max page $ page; // Current page $ pageset // Display count

$ Pageset = 10 display 10 clickable buttons () as follows


$ Pageshow // page number range

Hypothesis:
$ Maxpage = 20;
$ Page = 7
$ Pageset = 10;

$ Pageshow = array );


$ Pageshow how can we calculate it?


Reply to discussion (solution)

$ Page-5 to $ page + 4
The front and back of the page is near the end of the page.

Test

$page = 7;$maxpage = 20;$pageset = 10;for($page=1; $page<=20; $page++) {  $s = 1;  if($page > $pageset / 2) $s = $page - $pageset / 2;  if($maxpage - $page < $pageset / 2) $s = $maxpage - $pageset + 1;  $pageshow = range($s, $s + $pageset - 1);  printf("%d : %s\n", $page, join(' ', $pageshow));}
1 : 1 2 3 4 5 6 7 8 9 102 : 1 2 3 4 5 6 7 8 9 103 : 1 2 3 4 5 6 7 8 9 104 : 1 2 3 4 5 6 7 8 9 105 : 1 2 3 4 5 6 7 8 9 106 : 1 2 3 4 5 6 7 8 9 107 : 2 3 4 5 6 7 8 9 10 118 : 3 4 5 6 7 8 9 10 11 129 : 4 5 6 7 8 9 10 11 12 1310 : 5 6 7 8 9 10 11 12 13 1411 : 6 7 8 9 10 11 12 13 14 1512 : 7 8 9 10 11 12 13 14 15 1613 : 8 9 10 11 12 13 14 15 16 1714 : 9 10 11 12 13 14 15 16 17 1815 : 10 11 12 13 14 15 16 17 18 1916 : 11 12 13 14 15 16 17 18 19 2017 : 11 12 13 14 15 16 17 18 19 2018 : 11 12 13 14 15 16 17 18 19 2019 : 11 12 13 14 15 16 17 18 19 2020 : 11 12 13 14 15 16 17 18 19 20

Test

$page = 7;$maxpage = 20;$pageset = 10;for($page=1; $page<=20; $page++) {  $s = 1;  if($page > $pageset / 2) $s = $page - $pageset / 2;  if($maxpage - $page < $pageset / 2) $s = $maxpage - $pageset + 1;  $pageshow = range($s, $s + $pageset - 1);  printf("%d : %s\n", $page, join(' ', $pageshow));}
1 : 1 2 3 4 5 6 7 8 9 102 : 1 2 3 4 5 6 7 8 9 103 : 1 2 3 4 5 6 7 8 9 104 : 1 2 3 4 5 6 7 8 9 105 : 1 2 3 4 5 6 7 8 9 106 : 1 2 3 4 5 6 7 8 9 107 : 2 3 4 5 6 7 8 9 10 118 : 3 4 5 6 7 8 9 10 11 129 : 4 5 6 7 8 9 10 11 12 1310 : 5 6 7 8 9 10 11 12 13 1411 : 6 7 8 9 10 11 12 13 14 1512 : 7 8 9 10 11 12 13 14 15 1613 : 8 9 10 11 12 13 14 15 16 1714 : 9 10 11 12 13 14 15 16 17 1815 : 10 11 12 13 14 15 16 17 18 1916 : 11 12 13 14 15 16 17 18 19 2017 : 11 12 13 14 15 16 17 18 19 2018 : 11 12 13 14 15 16 17 18 19 2019 : 11 12 13 14 15 16 17 18 19 2020 : 11 12 13 14 15 16 17 18 19 20


$ Pageset = an error occurs when the singular value is set;
$ Pageset is variable

Take down the integers. constants are not used in the formula.

$maxpage = 20;$pageset = 7;for($page=1; $page<=20; $page++) {  $s = 1;  if($page > $pageset / 2) $s = $page - floor($pageset / 2);  if($maxpage - $page < $pageset / 2) $s = $maxpage - $pageset + 1;  $pageshow = range($s, $s + $pageset - 1);  printf("%d : %s\n", $page, join(' ', $pageshow));}

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.