Paging

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sequenced
Forum Newbie
Posts: 1
Joined: Sun Dec 04, 2005 9:04 pm

Paging

Post by sequenced »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi.
Can'f figure out some math 

I need to modify existing paging on one site.
Now it shows all pages - 1 | 2 | 3 | 4 | ... | 35 | 36, etc.
I need it to display them in more comfortable way.
When first page is displayed - from 1 to 10 ([1] | 2 ... 10),
when, for example, 20th page - it should display 5 links to previous pages, current page, and 5 to next pages:
(16 | 17 | 18 | 19 | [20] | 21 | 22 | 23 | 24) - kind of that.
When last page - links to 10 previous pages (ex. 30 | 31 .. | 39 | [40]).
Hope you can understand my question, my english is horrible, i know 

Current code:

Code: Select all

if ($num>1)
{
	if($act<1) $act = 1;
	echo "<tr><td>";
	for($i=1; $i<=$num; $i++)
	{
		if($i==$act)
			echo "<a class = \"youProfile\" style=\"font-weight: bold;\">" .$i. "</a>";
		else
			echo "<a class = \"youProfile\" href=\"" .$url. $param. "=" .$i. "\">" .$i. "</a>";
		echo " | ";
	}
	echo "</td></tr>";
}
$num - total number of pages
$act - current page

So, i can't figure out what "if" conditions should i put to check display link, or not..

Thanks :)


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

I'm too lazy to do the code for you, but here's a few pointers:

- You need to display x number of pages to the left and right of your current page. Remember to check that the lowest page is not below 2 and the highest page is not above the total number of pages - 1.
- Allways display page 1 and the last page. (The reason I chose 2 as the first and # pages - 1 as the last).
- If the lowest page to the left of the current page is greater than 2, display '...' after page 1.
- Same as above but current page greater than # of pages.

Voila.

If you can't figure it out from there, as a last resort, beg on your knees and I'll do it for you. :wink:
Post Reply