Search for advanced php / mysql script pagination

I am looking for an "advanced" php Pagination script that shows me 10 mysql records per page. There are many โ€œsimpleโ€ scripts on the network (even with jQuery), such as: 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 you have hundreds of entries ... So, I need 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 

etc.

Many forums or blogs (such as wordpress) use this technique. Can someone please provide me the code? There should be a โ€œbest practice codeโ€, but I canโ€™t find it. Thanks!

+4
source share
4 answers

Try it,

 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; } 
+5
source

If you really have 100 pages of results, you may need to paginate logarithmically.
See this post for more details.

+1
source

Check out this plugin (jquery)

The paginator is a little different from what you want, but it will do everything you need.

0
source
0
source

Source: https://habr.com/ru/post/1301567/


All Articles