PHP function to achieve paging effect, php text paging and number paging

WBOY
Release: 2016-07-25 08:52:33
Original
1497 people have browsed it
  1. //Paging
  2. /**
  3. * $pageType paging type 1 is numeric paging 2 is text paging
  4. * You can pass $pageTotal, $page, $total and other data as parameters, or use it as a global variable in paging (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'
' ;
  • }
  • else if($pageType == 2)
  • {
  • echo '
    ';
  • echo '
  • //Paging parameter packaging/*** $sql can obtain a sql statement of the total number of data * $size displays the number of items on each page

    */

    function pageParam($sql,$size)

    {

    //Set all involved parameters to global variables
    // $pagestart someone Where does a page start
    // $total total number of records $page a certain page $pageTotal total number of pages
      global $pagestart,$pagesize,$total,$page,$pageTotal;
    1. $pagesize = $size;
    2. // Get the total number of data
    3. $total = mysql_num_rows(queryDB($sql));
    4. // Error handling, first determine whether it exists
    5. if(isset($_GET['page']))
    6. {
    7. // A specific page
    8. $page = $_GET['page'];
    9. // Determine whether it is empty (0 is empty)/less than 0/whether it is a number
    10. if(empty($page) || $page < 0 || !is_numeric ($page))
    11. {
    12. $page = 1;
    13. }
    14. else
    15. {
    16. $page = intval($page); //Rounding to prevent decimals from appearing
    17. }
    18. }
    19. else
    20. {
    21. //Initialization Display page 1
    22. $page = 1;
    23. }
    24. // Clear database
    25. if($total == 0)
    26. {
    27. // Set to 1
    28. $pageTotal = 1;
    29. }
    30. else
    31. {
    32. / / The total number of pages in paging (further rounded up)
    33. $pageTotal = ceil($total / $pagesize);
    34. }
    35. // The number of pages is greater than the total page number $total
    36. if($page > $pageTotal)
    37. {
    38. $page = $pageTotal;
    39. }
    40. // When the page starts from a certain record
    41. $pagestart = ($page - 1) * $pagesize;
    42. }
    43. Copy code
    44. Parameter explanation: $pagestart is when the page starts from a certain record, $pagesize is the number of records displayed on each page
    45. 3. During use, call pageParam first, then call paging
    /*** The first one can get a sql statement of the total number of data * The second one can display the number of items on each page
    */

    pageParam("select userid from user",2);

    //Paging type 1 is numeric paging 2 is text paging

    paging(2 );
    ?>

    1. Copy code
    2. 4. The calling location is selected according to the specific situation, and the text is paginated:
    3. //Paging type 1 is digital paging 2 is text paging
    paging(1);?>Copy code


    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template