这些简单的脚本在包含数百个条目时是不好的……所以我需要一个高级脚本-我需要这样的东西:在第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;}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.htmlHere is a demo: http://demos.9lessons.info/pagination.phpThese 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 ... 45On Page 8:1 ... 6 7 [8] 9 10 ... 45On Page 43:1 ... 41 42 [43] 44 45and 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分页脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 04:01