• <legend id='zQom1'><style id='zQom1'><dir id='zQom1'><q id='zQom1'></q></dir></style></legend>
    <tfoot id='zQom1'></tfoot>
  • <i id='zQom1'><tr id='zQom1'><dt id='zQom1'><q id='zQom1'><span id='zQom1'><b id='zQom1'><form id='zQom1'><ins id='zQom1'></ins><ul id='zQom1'></ul><sub id='zQom1'></sub></form><legend id='zQom1'></legend><bdo id='zQom1'><pre id='zQom1'><center id='zQom1'></center></pre></bdo></b><th id='zQom1'></th></span></q></dt></tr></i><div id='zQom1'><tfoot id='zQom1'></tfoot><dl id='zQom1'><fieldset id='zQom1'></fieldset></dl></div>

    <small id='zQom1'></small><noframes id='zQom1'>

          <bdo id='zQom1'></bdo><ul id='zQom1'></ul>

        搜索高级 php/mysql 分页脚本

        时间:2023-09-24
          <tbody id='O0VdD'></tbody>

          <i id='O0VdD'><tr id='O0VdD'><dt id='O0VdD'><q id='O0VdD'><span id='O0VdD'><b id='O0VdD'><form id='O0VdD'><ins id='O0VdD'></ins><ul id='O0VdD'></ul><sub id='O0VdD'></sub></form><legend id='O0VdD'></legend><bdo id='O0VdD'><pre id='O0VdD'><center id='O0VdD'></center></pre></bdo></b><th id='O0VdD'></th></span></q></dt></tr></i><div id='O0VdD'><tfoot id='O0VdD'></tfoot><dl id='O0VdD'><fieldset id='O0VdD'></fieldset></dl></div>
        • <tfoot id='O0VdD'></tfoot>

            <small id='O0VdD'></small><noframes id='O0VdD'>

            <legend id='O0VdD'><style id='O0VdD'><dir id='O0VdD'><q id='O0VdD'></q></dir></style></legend>

              • <bdo id='O0VdD'></bdo><ul id='O0VdD'></ul>

                  本文介绍了搜索高级 php/mysql 分页脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在寻找一个高级"的 php 分页脚本,每页显示 10 个 mysql 条目.在网络上有许多简单"脚本(即使使用 jQuery),如下所示: http://www.9lessons.info/2009/09/pagination-with-jquery-mysql-and-php.html这是一个演示:http://demos.9lessons.info/pagination.php>

                  当有数百个条目时,这些简单的脚本很糟糕......所以我需要一个高级脚本 - 我需要这样的东西:

                  当您在第 1 页时,它应该如下所示:

                  [1] 2 3 4 5 ... 45

                  在第 8 页:

                  1 ... 6 7 [8] 9 10 ... 45

                  第 43 页:

                  1 ... 41 42 [43] 44 45

                  等等...

                  许多论坛或博客(例如 wordpress)都在使用这种技术.有人可以给我提供代码吗?一定有最佳实践代码",但我找不到.谢谢!

                  解决方案

                  试试这个,

                  function generatePagination($currentPage, $totalPages, $pageLinks = 5){如果 ($totalPages <= 1){返回空;}$html = '
                    ';$leeway = floor($pageLinks/2);$firstPage = $currentPage - $leeway;$lastPage = $currentPage + $leeway;如果 ($firstPage <1){$lastPage += 1 - $firstPage;$第一页 = 1;}如果 ($lastPage > $totalPages){$firstPage -= $lastPage - $totalPages;$lastPage = $totalPages;}如果 ($firstPage <1){$第一页 = 1;}如果 ($firstPage != 1){$html .= '<li class="first"><a href="./?p=1" title="第1页">1</a></li>';$html .= '<li class="页面点"><span>...</span></li>';}for ($i = $firstPage; $i <= $lastPage; $i++){如果 ($i == $currentPage){$html .= '<li class="当前页面"><span>'.$i .'</span></li>';}别的{$html .= '<li class="page"><a href="./?p='. $i .'" title="页面' . $i .'">'.$i .'</a></li>';}}如果 ($lastPage != $totalPages){$html .= '<li class="页面点"><span>...</span></li>';$html .= '<li class="last"><a href="./?p='. $totalPages .'" title="页面' . $totalPages . '">'.$totalPages .'</a></li>';}$html .= '</ul>';返回 $html;}

                  I'm searching for a "advanced" php Pagination script, that shows me 10 mysql entries per page. In the web there are many "simple" scripts (even with jQuery) like this: http://www.9lessons.info/2009/09/pagination-with-jquery-mysql-and-php.html Here is a demo: http://demos.9lessons.info/pagination.php

                  These simple scripts are bad when having hundreds of entries... So what I need is an advanced script - I need something like this:

                  When you are on Page 1 it should look like this:

                  [1] 2 3 4 5 ... 45
                  

                  On Page 8:

                  1 ... 6 7 [8] 9 10 ... 45
                  

                  On Page 43:

                  1 ... 41 42 [43] 44 45
                  

                  and so on...

                  Many forums or blogs (e.g. wordpress) are using this technique. Can somebody please provide me with the code? There must be a "best practise code", but I can't find it. Thanks!

                  解决方案

                  Try this out,

                  function generatePagination($currentPage, $totalPages, $pageLinks = 5)
                  {
                      if ($totalPages <= 1)
                      {
                          return NULL;
                      }
                  
                      $html = '<ul class="pagination">';
                  
                      $leeway = floor($pageLinks / 2);
                  
                      $firstPage = $currentPage - $leeway;
                      $lastPage = $currentPage + $leeway;
                  
                      if ($firstPage < 1)
                      {
                          $lastPage += 1 - $firstPage;
                          $firstPage = 1;
                      }
                      if ($lastPage > $totalPages)
                      {
                          $firstPage -= $lastPage - $totalPages;
                          $lastPage = $totalPages;
                      }
                      if ($firstPage < 1)
                      {
                          $firstPage = 1;
                      }
                  
                      if ($firstPage != 1)
                      {
                          $html .= '<li class="first"><a href="./?p=1" title="Page 1">1</a></li>';
                          $html .= '<li class="page dots"><span>...</span></li>';
                      }
                  
                      for ($i = $firstPage; $i <= $lastPage; $i++)
                      {
                          if ($i == $currentPage)
                          {
                              $html .= '<li class="page current"><span>' . $i . '</span></li>';
                          }
                          else
                          {
                              $html .= '<li class="page"><a href="./?p=' . $i . '" title="Page ' . $i . '">' . $i . '</a></li>';
                          }
                      }
                  
                      if ($lastPage != $totalPages)
                      {
                          $html .= '<li class="page dots"><span>...</span></li>';
                          $html .= '<li class="last"><a href="./?p=' . $totalPages . '" title="Page ' . $totalPages . '">' . $totalPages . '</a></li>';
                      }
                  
                      $html .= '</ul>';
                  
                      return $html;
                  }
                  

                  这篇关于搜索高级 php/mysql 分页脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 Jquery、PHP、Mysql 进行 Ajax 分页 下一篇:如何为无限滚动的查询结果分页?

                  相关文章

                1. <tfoot id='Z8869'></tfoot>

                  <i id='Z8869'><tr id='Z8869'><dt id='Z8869'><q id='Z8869'><span id='Z8869'><b id='Z8869'><form id='Z8869'><ins id='Z8869'></ins><ul id='Z8869'></ul><sub id='Z8869'></sub></form><legend id='Z8869'></legend><bdo id='Z8869'><pre id='Z8869'><center id='Z8869'></center></pre></bdo></b><th id='Z8869'></th></span></q></dt></tr></i><div id='Z8869'><tfoot id='Z8869'></tfoot><dl id='Z8869'><fieldset id='Z8869'></fieldset></dl></div>
                  • <bdo id='Z8869'></bdo><ul id='Z8869'></ul>

                  <small id='Z8869'></small><noframes id='Z8869'>

                      <legend id='Z8869'><style id='Z8869'><dir id='Z8869'><q id='Z8869'></q></dir></style></legend>