Algorithm: Limiting Large Numbers of Pages to 10 visible
| From: | Lara J. Fabans | Date: | Fri, 21 Dec 2001 04:16:37 +0000 |
| Subject: | Algorithm: Limiting Large Numbers of Pages to 10 visible | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-78396@lists.php.net to get a copy of this message | ||
Hi,
I need an algorithm for paging. If I have 100 pages of results, I only want to show
<< Prev 1 2 3 4 5 6 7 8 9 10 Next >>
Where I limit the number to 10 results of pages, but I cannot figure it out for the life of me.
for ($i = $page; $i <= ($page+10); $i++) {
if ($i != $page) {
echo " <a href=\"$PHP_SELF?catid=$catid&page=$i\">$i</a> ";} else {
echo " $i ";} }
echo " <a href=\"$PHP_SELF?catid=$catid&page=$i\">>></a> ";
echo " <a href=\"$PHP_SELF?catid=$catid&page=$num_pages\">End</a> ";
}
But what I need to do is not show pages that aren't there, and I'm hardwiring it to show
10 whether they exist or not.
I've got to believe that there's a really slick way of doing this. I've searched the usual
places (weberdev.com, devshed.com, zend.com) but there's no really good keywords,
and when you search on 'paging" you get too many results to be useful
Thanks in advance,
Lara
---------------------
Lara J. Fabans
Lodestone Software, Inc
lara@lodestone-sw.com