簡體   English   中英

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

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

我想知道如何在此分頁中添加下一頁、上一頁、第一頁和最后一頁。 下面的代碼只顯示頁碼,不顯示下一頁、上一頁、第一頁和最后一頁。

    <?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--;
            }

            ?>

我不知道這是否有幫助..但也許你可以用它做點什么:)

 <?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