PHP分页显示的项目显示范围

Display range of items displayed in PHP pagination

我在我的页面中设置了分页,限制为每页显示 12 个项目。我现在的问题是如何显示页面中显示的项目范围。这是我的代码以及到目前为止我尝试过的代码:

<div class="search_hits flex_box">
                      @if(count($result) == 0)
                        <p>No result found.</p>
                      @else
                        <p>検索結果{{$total}}件ヒット</p>
                        <p>Showing {{floor(count($result) / 12) + (count($result) % 12)}}items</p>
                        </div>
                        <ul class="projects">
                          @foreach ($result as $detail)
                            <li>
                                <a href="../contests/details/index.html">
                                <div class="prjct_title">
                                    <p>{{ $detail['contest_name'] }}</p>
                                </div>
                                <div class="calc_height_o">
                                    <div class="calc_height_i">
                                      <div class="fitimg"><img src="{{ isset($detail->photos['0']) ? $detail->photos['0']['contest_photo'] : ''}}"></div>
                                    </div>
                                </div>
                                <div class="prjct_btc">
                                    <p>Prize BTC for {{ $detail['total_prize'] }}LPY</p>
                                </div>
                                </a>
                            </li>
                          @endforeach
                        </ul><!--projects END-->
                      @endif

                    @if ($result->hasPages())
                      <ul class="pagenation">
                          {{-- Previous Page Link --}}
                          @if ($result->onFirstPage())
                              <li class="disabled"><span>«</span></li>
                          @else
                              <li><a href="{{ $result->previousPageUrl() }}" rel="prev">«</a></li>
                          @endif

                          @foreach(range(1, $result->lastPage()) as $i)
                              @if($i == 1)
                                  @if($i == $result->currentPage())
                                      <li class="active"><span>{{ $i }}</span></li>
                                  @else
                                      <li><a href="{{ $result->url($i) }}">{{ $i }}</a></li>
                                  @endif
                              @elseif($i == $result->lastPage())
                                  @if($i == $result->currentPage())
                                      <li class="active"><span>{{ $i }}</span></li>
                                  @else
                                      <li><a href="{{ $result->url($i) }}">{{ $i }}</a></li>
                                  @endif
                              @elseif($i >= $result->currentPage() - 2 && $i <= $result->currentPage() + 2)
                                  @if ($i == $result->currentPage())
                                      <li class="active"><span>{{ $i }}</span></li>
                                  @else
                                      @if($i == ($result->currentPage() - 1) || $i == ($result->currentPage() + 1) )
                                          <li><a href="{{ $result->url($i) }}">{{ $i }}</a></li>
                                      @else
                                          @if(($result->currentPage() - 2) > 1 || ( $result->currentPage() + 2 ) < $result->lastPage() )
                                              <li><span class="ellipsis">...</span></li>
                                          @endif
                                      @endif
                                  @endif
                              @endif
                          @endforeach

                          {{-- Next Page Link --}}
                          @if ($result->hasMorePages())
                              <li><a href="{{ $result->nextPageUrl() }}" rel="next">»</a></li>
                          @else
                              <li class="disabled"><span>»</span></li>
                          @endif
                      </ul>
                  @endif
                <!--pagenation END-->
                </div>

但是问题来了,一直显示Showing 2 items

<p>Showing {{floor(count($result) / 12) + (count($result) % 12)}}items</p>

我想要的输出是这样的,如果我有 18 个结果,第一页将显示 Showing 1~12 items,第二页将显示 Showing 13~18 items

我找到了一些答案 here 但它似乎显示在分页下方,但在我的情况下,它显示在结果的顶部。

好的。我发现了一些技巧。我是这样做的:

<p>
  Showing
  @if ($result->onFirstPage())
      {{1 . '~' . 12}}
  @else
      {{(($result->currentPage()-1)*12)+1 . '~' . $result->currentPage() * 12}}
  @endif
  items
</p>

您可以根据需要进行修改。