【问题标题】:Searching for advanced php/mysql pagination script [closed]搜索高级 php/mysql 分页脚本 [关闭]
【发布时间】:2010-02-17 11:39:19
【问题描述】:
【问题讨论】:
标签:
php
mysql
pagination
paging
【解决方案1】:
试试这个,
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;
}
【解决方案3】:
看看 this 插件 (jquery)
分页器与您想要的有点不同,但它会满足您的所有需求。