简体   繁体   English

如何在分页中添加上一页、下一页、第一页、最后一页?

[英]How to Add Previous Page, Next Page, First Page, Last Page in the Pagination?

I want to know how can i add next page, previous page, first page and last page in this pagination.我想知道如何在此分页中添加下一页、上一页、第一页和最后一页。 Below code is only showing the page number it doesn't show next page, previous page, first page and last page.下面的代码只显示页码,不显示下一页、上一页、第一页和最后一页。

    <?php
            $pagesToShow = 10; 
            $pageSize = 20; 
            $numPages = ceil($numResults / $pageSize); 
            $pageLefts = min($pagesToShow, $numPages); 
            $currentPage = $page - floor( $pagesToShow / 2 ); 
            if($currentPage < 1){ 
                $currentPage = 1;
            }
            if($currentPage + $pageLefts > $numPages + 1) {
                $currentPage = $numPages + 1 - $pageLefts;
            }
            while($pageLefts != 0 && $currentPage <= $numPages) { 
                if($currentPage == $page){
                    echo "<div class='pageNumberContainer'>

                        <span class='pageNumber'>$currentPage</span>
                      </div>";
                }else{
                    echo "<div class='pageNumberContainer'>
                              <a href='search.php?term=$term&type=$type&page=$currentPage'>

                                <span class='pageNumber'>$currentPage</span>
                              </a>
                          </div>";
                }
                $currentPage++;
                $pageLefts--;
            }

            ?>

I dont know if this helps .. but maybe you can do something with it :)我不知道这是否有帮助..但也许你可以用它做点什么:)

 <?php      $pagesToShow = 10; 
        $pageSize = 20; 
        $numPages = ceil($numResults / $pageSize); 
        $pageLefts = min($pagesToShow, $numPages); 
        $currentPage = $page - floor( $pagesToShow / 2 ); 
        if($currentPage < 1){ 
            $currentPage = 1;
        }
        if($currentPage + $pageLefts > $numPages + 1) {
            $currentPage = $numPages + 1 - $pageLefts;
        }
        if ($numPages > 1){echo 'FirstPage = 1';}
        while($pageLefts != 0 && $currentPage <= $numPages) { 
            if($currentPage == $page){

                echo "<div class='pageNumberContainer'>

                    <span class='pageNumber'>Current Page Number Is: ".$currentPage</span>
                  </div>";
            }else{

                if ($currentPage != 1){$previousPage = $currentPage - 1; echo 
'PREVIOUS PAGE:' . $previousPage; }
                echo "<div class='pageNumberContainer'>
                          <a href='search.php?term=".$term."&type=".$type."&page=".$currentPage."'>

                            <span class='pageNumber'>CURRENT PAGE: ".$currentPage." </span>
                          </a>
                      </div>";
                if ($currentPage != $numPages){$nextPage = $currentPage + 1; echo 'NEXT PAGE:' . $nextPage; }     

            }
            $currentPage++;
            $pageLefts--;
        }
        if ($numPages > 1){echo 'LastPage = '.$numPages;}
       ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM