Searching for advanced php/mysql pagination script(搜索高级 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="56ysMemhtQ==">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="6aG16Z2i" . $i .'">'.$i .'</a></li>';}}如果 ($lastPage != $totalPages){$html .= '<li class="页面点"><span>...</span></li>';$html .= '<li class="last"><a href="./?p='. $totalPages .'" title="6aG16Z2i" . $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="UGFnZSAx">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="UGFnZSA=" . $i . '">' . $i . '</a></li>';
}
}
if ($lastPage != $totalPages)
{
$html .= '<li class="page dots"><span>...</span></li>';
$html .= '<li class="last"><a href="./?p=' . $totalPages . '" title="UGFnZSA=" . $totalPages . '">' . $totalPages . '</a></li>';
}
$html .= '</ul>';
return $html;
}
这篇关于搜索高级 php/mysql 分页脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:搜索高级 php/mysql 分页脚本
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01