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

Learn PHP paging code examples_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:56834browse

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 .= "