Jump to content

pagination links


adamlacombe

Recommended Posts

I was wondering if there is a way to have the page links like: 1 2 3 ... 7 8 9 ... 13 14 15 .....

 

So they aren't all there.

 

Right now the code looks like this:

for ($i = 1; $i <= $page_count; ++$i) {
    echo '<a href="user.php?action=comments&page=' . $i . '">'
        . $i . '</a> ';
} 

 

Is there like some kind of php math function?

 

Thanks In Advanced!

Link to comment
Share on other sites

Math? Yes, there are plenty of math functions, but what you need is logic to create that functionality. I'm assuming that in your example the last set of ellipses are not part of the output you want and the example represents what you would see when the current page is page 8? So, it always shows first three pages, the current page with prev/next and then the last three pages. So, on page 7 it would look like this?

1 2 3 ... 6 7 8 ... 13 14 15

 

That's not too difficult, but you need to decide what happens if the user is on one of the first/last few pages or if ther are only a small number of pages

Link to comment
Share on other sites

First off you would need to determine what page you are currently browsing, ie page 1, 4, 5, 10 etc...

 

Then you base your logic off of that.

 

Essentially creating 3 sets,

 

set a would be 1,2,3

set b would be curpage-1, curpage, curpage+1

set c would be page_count-2,page_count-1,page_count

 

The tricky part comes here, what if your browsing page 1,2,3,13,14, or 15 then what do you display?

 

Generally you see these methods where that have 1,2,3 ... Next and when you click on next it brings up results 4,5,6.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.