首页 / PHP / 搜索高级php / mysql分页脚本
搜索高级php / mysql分页脚本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了搜索高级php / mysql分页脚本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1651字,纯文字阅读大概需要3分钟。
内容图文
我正在寻找一个“高级”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)
{
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分页脚本全部内容,希望文章能够帮你解决搜索高级php / mysql分页脚本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。