Home > Backend Development > PHP Tutorial > Learn PHP paging code examples_PHP tutorial

Learn PHP paging code examples_PHP tutorial

WBOY
Release: 2016-07-13 10:25:56
Original
823 people have browsed it

There are many ways to paginate in PHP. Today we will use a small example to demonstrate this function.

Copy code The code is as follows:

$result = "
< ul class="fn-clear">";

// Previous page
if ($offset>0) {
$result .= "

  • ;a href="".$url.'offset='.($offset-$maxrow)."">Prev
                                                                                    🎜> $pages = $allPageNums; //Total number of pages
    $page = $curPage; //Current page number
    $page_len = 9;
    $page_len = ($page_len%2)?$page_len :$pagelen+1;//Number of page numbers
    $pageoffset = ($page_len-1)/2;//Offset to the left and right of page number
    if($pages>$page_len){
    //If the current page is less than or equal to the left offset
                                                                                                                                                                                   The page is greater than the left offset
    //If the right offset of the current page number exceeds the maximum number of pages
    if($page+$pageoffset>=$pages+1){
    $init = $pages-$page_len+ 1;
        $max_p = $pages;           $max_p = $page+ $pageoffset;
    } }
    } }
    } else {

    for($i=$init; $i<=$max_p; $i++) {

    if ( $i == $curPage ) {
    $result .= "
  • php pagination
  • 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