问题描述
.
//Prev
.
for($number = 1; $number <= $num_pages; $number++)
{
if($page == $number)
{
$navigator .= "<b>[$number]</b> ";
}
else
{
$navigator .= "<a href='?c=".$_SESSION['cID']".&rows=".$per_page."&page=$number'>$number</a> ";
}
}
.
//Next
.
这是打印页数的代码段.
This is the snippet that prints number of pages.
示例输出:
上一个1 2 3 4 [5] 6 7 8 9 10下一个
Previous 1 2 3 4 [5] 6 7 8 9 10 Next
5是当前页面.
问题:页面编号按顺序显示,没有任何限制.如果我有100页,则会显示所有数字.
Problem: page numbers are shown in sequence with no restrictions. If i have 100 pages, all numbers show up.
问题:我需要我的分页号码显示如下...
Question: I need my paging numbers appear as the following...
假设我们只有7($ num_pages)页:
上一个1 2 [3] 4 5 6 7下一个
Previous 1 2 [3] 4 5 6 7 Next
假设我们有90页:
Assume we have 90 pages:
[1] 2 3 4 5 6 7 ... 90下一页
[1] 2 3 4 5 6 7 ... 90 Next
假设用户点击了第七页:
Assume user clicked the 7th page:
上一个1 ... 5 6 [7] 8 9 10 11 ... 90下一个
Previous 1 ... 5 6 [7] 8 9 10 11 ... 90 Next
假设用户点击了第11页:
Assume user clicked 11th page:
上一个1 ... 9 10 [11] 12 13 14 15 ... 90下一个
Previous 1 ... 9 10 [11] 12 13 14 15 ... 90 Next
假设用户点击了第15页:
Assume user clicked 15th page:
上一个1 ... 13 14 [15] 16 17 18 19 ... 90下一个
Previous 1 ... 13 14 [15] 16 17 18 19 ... 90 Next
假设用户点击了第90页:
Assume user clicked 90th page:
上一个1 ... 84 85 86 87 88 89 [90]
Previous 1 ... 84 85 86 87 88 89 [90]
任何帮助将不胜感激.
推荐答案
这应该足以使您至少起步
This should be more than enough to get you started at least
$count = 7; // number to show
// start at half threshold down from the current location.
$number = $current - round($count/2);
if( $number > 1 ) echo '...';
else $ // increase to have number start at 1.
for( $number; $number < $number + $count; $number++)
{
// your for loop as normal
}
if( $number < $total ) echo '...';
这篇关于在PHP分页中添加省略号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!