PHP functions for paging effects, PHP text paging and digital paging

Source: Internet
Author: User
  1. Page out
  2. /**
  3. * $pageType Paging Type 1 is the number page 2 is the text paging
  4. * $pagetotal, $page, $total and other data can be passed as parameters, or in paging as global variables (recommended)
  5. */
  6. function Paging ($pageType)
  7. {
  8. Global $pageTotal, $page, $total;
  9. if ($pageType = = 1)
  10. {
  11. Echo ';
  12. Echo '
      ;
    • for ($i =0; $i < $pageTotal; $i + +)
    • {
    • if ($page = = ($i + 1))
    • {
    • Echo '
    • '. ($i + 1). '
    • ';
    • }
    • Else
    • {
    • Echo '
    • '. ($i + 1). '
    • ';
    • }
    • }
    • Echo
    ';
  13. Echo ';
  14. }
  15. else if ($pageType = = 2)
  16. {
  17. Echo ';
  18. Echo '
      ;
    • Echo '
    • '. $page. ' /'. $pageTotal. ' Page |
    • ';
    • Echo '
    • A total of '. $total. ' A Member |
    • ';
    • First page
    • if ($page = = 1)
    • {
    • Echo '
    • Home |
    • ';
    • Echo '
    • Prev |
    • ';
    • }
    • Else
    • {
    • $_server["Script_name"] gets the current script name for easy porting
    • You can also customize constants, constant values and script filenames are consistent
    • Echo '
    • Home |
    • ';
    • Echo '
    • Prev |
    • ';
    • }
    • Last page
    • if ($page = = $pageTotal)
    • {
    • Echo '
    • Next Page |
    • ';
    • Echo '
    • End |
    • ';
    • }
    • Else
    • {
    • Echo '
    • Next Page |
    • ';
    • Echo '
    • End |
    • ';
    • }
    • Echo '
    ';
  19. Echo ';
  20. }
  21. }
Copy Code

Parameter interpretation: $pageTotal is the total number of pages, $page is the current page, $total is the total amount of data obtained from the database;

2, the parameters are all encapsulated

  1. Split-page parameter loading
  2. /**
  3. * $sql An SQL statement that can get the total number of data
  4. * $size show the number of bars per page
  5. */
  6. function Pageparam ($sql, $size)
  7. {
  8. Set the global variables for all the parameters involved
  9. $pagestart where a page starts
  10. $total total number of records $page a page $pageTotal total pages
  11. Global $pagestart, $pagesize, $total, $page, $pageTotal;
  12. $pagesize = $size;
  13. Get Total data
  14. $total = Mysql_num_rows (Querydb ($sql));
  15. Error handling, first determine if there is
  16. if (Isset ($_get[' page '))
  17. {
  18. A specific page
  19. $page = $_get[' page '];
  20. Determines whether it is empty (0 is empty)/less than 0/whether it is a number
  21. if (Empty ($page) | | $page < 0 | |!is_numeric ($page))
  22. {
  23. $page = 1;
  24. }
  25. Else
  26. {
  27. $page = Intval ($page); Rounding to prevent decimals from appearing
  28. }
  29. }
  30. Else
  31. {
  32. Initialization shows page 1th
  33. $page = 1;
  34. }
  35. Database zeroing
  36. if ($total = = 0)
  37. {
  38. Set to 1
  39. $pageTotal = 1;
  40. }
  41. Else
  42. {
  43. The total number of pages in the page (in-one rounding)
  44. $pageTotal = Ceil ($total/$pagesize);
  45. }
  46. Pages larger than total page $total
  47. if ($page > $pageTotal)
  48. {
  49. $page = $pageTotal;
  50. }
  51. When a page starts from a record
  52. $pagestart = ($page-1) * $pagesize;
  53. }
Copy Code

Parameter interpretation: $pagestart is when a page starts from a record, $pagesize is the number of records displayed per page

3, in use, call Pageparam First, and then call paging

    1. /**
    2. * The first SQL statement to get the total number of data
    3. * The second each page shows the number of bars
    4. */
    5. Pageparam ("Select userid from User", 2);
    6. Paging Type 1 is a number page 2 is a text paging
    7. Paging (2);
    8. ?>
Copy Code

4, the call location according to the specific circumstances of choice, the text page:

    1. Paging Type 1 is a number page 2 is a text paging
    2. Paging (1);
    3. ?>
Copy Code
  • 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.