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
https://forums.phpfreaks.com/topic/167173-pagination-links/
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
https://forums.phpfreaks.com/topic/167173-pagination-links/#findComment-881465
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
https://forums.phpfreaks.com/topic/167173-pagination-links/#findComment-881484
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.