adamlacombe Posted July 23, 2009 Share Posted July 23, 2009 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! Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 23, 2009 Share Posted July 23, 2009 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 Quote Link to comment Share on other sites More sharing options...
adamlacombe Posted July 23, 2009 Author Share Posted July 23, 2009 nope they aren't. But how would I go about doing that? I have always had a difficult time with paginiation's Quote Link to comment Share on other sites More sharing options...
ldougherty Posted July 23, 2009 Share Posted July 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.