Php array Function implementation php paging-php Tutorial

Source: Internet
Author: User
Php array function for php paging

  1. // Php paging code
  2. $ Array = array ("1", "2", "3", "4", "5", "6", "7", "8 ", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18 ", "19", "20"); // specifies the array to be paged
  3. $ Page = $ _ GET ['Page'];
  4. $ R = $ this-> page ($ array, 5, $ page );
  5. Print_r ($ r );
  6. Exit ();
  7. Foreach ($ r ["source"] as $ s ){
  8. Echo $ s;
  9. }
  10. Function page ($ array, $ pagesize, $ current ){
  11. $ _ Return = array ();
  12. $ Total = ceil (Count ($ array)/$ pagesize); // calculates the total number of pages
  13. $ Prev = ($ current-1) <= 0? "1" :( $ current-1); // confirm the previous page. if the current page is the first page, click to display the first page.
  14. $ Next = ($ current + 1) >=$ total? $ Total: $ current + 1); // confirm the next page. if the current page is the last page, click the next page to display the last page.
  15. $ Current = ($ current> ($ total )? ($ Total): $ current); // if the current page is greater than the total page number, the current page is the last page
  16. $ Start = ($ current-1) * $ pagesize; // The number of items that should be read from the page.
  17. For ($ I = $ start; $ I <($ start + $ pagesize); $ I ++ ){
  18. Array_push ($ _ return, $ array [$ I]); // put the displayed information into the array $ _ return
  19. }
  20. $ Pagearray ["source"] =$ _ return;
  21. $ Pagearray ["page"] = "first \"> prev next end "; // The page style can be adjusted as needed
  22. Return $ pagearray;
  23. }

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.