| | |
How to use large pagination in a limited area
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Currently, when you're on Page 9, the link is displayed like this:
«« First « Prev 6 7 8 9 10 11 12 13 14 Next » Last »»
This is better, cuz the visitor will have the last 3 previous page, and the next 5 pages...
So You want this:
«« First « Prev 9 10 11 12 13 14 15 16 17 Next » Last »»
When you're on page9 right?
EDIT{}
Here:
«« First « Prev 6 7 8 9 10 11 12 13 14 Next » Last »»
This is better, cuz the visitor will have the last 3 previous page, and the next 5 pages...
So You want this:
«« First « Prev 9 10 11 12 13 14 15 16 17 Next » Last »»
When you're on page9 right?
EDIT{}
Here:
PHP Syntax (Toggle Plain Text)
<style type="text/css"> .pagination{ padding: 2px; } .pagination ul{ margin: 0; padding: 0; text-align: left; /*Set to "right" to right align pagination interface*/ font-size: 16px; } .pagination li{ list-style-type: none; display: inline; padding-bottom: 1px; } .pagination a, .pagination a:visited{ padding: 0 5px; border: 1px solid #9aafe5; text-decoration: none; color: #2e6ab1; } .pagination a:hover, .pagination a:active{ border: 1px solid #2b66a5; color: #000; background-color: #FFFF80; } .pagination a.currentpage{ background-color: #2e6ab1; color: #FFF !important; border-color: #2b66a5; font-weight: bold; cursor: default; } .pagination a.disablelink, .pagination a.disablelink:hover{ background-color: white; cursor: default; color: #929292; border-color: #929292; font-weight: normal !important; } .pagination a.prevnext{ font-weight: bold; } </style>
php Syntax (Toggle Plain Text)
<?php if(isset($_GET["page"])) { $page = $_GET["page"]; } else { $page = 1; } $totalPages = 50; function paging($page, $totalPages) { $printPages = 9; //Show only X pages $i = 1; $previous_page = ($page > 1) ? $page - 1 : 1; $next_page = $page + 1; if($totalPages < $printPages) { $printPages = $totalPages; } echo '<div class="pagination" align="center"> <ul>'; if($page > 1) { echo ' <li><a href="?page=1">«« First</a></li> '; echo ' <li><a href="?page='.$previous_page.'">« Prev</a></li> '; if($totalPages > 0) { //Nothing for now, used to have a | separator here } } if($page - $printPages <= 0) { $currentPage = 1; } elseif($page > 3 && $page + ($printPages -1) < $totalPages) { $currentPage = $page; } else { $currentPage = $totalPages - ($printPages - 1); } while($i <= $printPages) { echo '<li><a'; if($page == $currentPage) { echo ' class="currentpage" '; } echo ' href="?page='.$currentPage.'"> '.$currentPage.' </a></li> '; $currentPage++; $i++; } if($page < $totalPages) { $next = $page + 1; echo ' <li><a href="?page='.$next.'">Next »</a></li> '; echo ' <li> <a href="?page='.$totalPages.'">Last »»</a></li> '; } echo '</ul></div>'; } //Use it paging($page, $totalPages) ?>
Last edited by smartness; Sep 19th, 2009 at 6:57 am.
![]() |
Similar Threads
- Dragging images in limited area (JavaScript / DHTML / AJAX)
- Cyberstalking (Network Security)
- Math Functions (C++)
- com vs. exe (Assembly)
- print large pricturebox or form in vb6 (Visual Basic 4 / 5 / 6)
- Do you need AV and Firewall? (Windows NT / 2000 / XP)
- Talk Terminal Command (OS X)
- Computer freezes when i try to install windows XP (Windows NT / 2000 / XP)
Other Threads in the PHP Forum
- Previous Thread: Help debug Random property script.
- Next Thread: Search from text box and saving to txt file
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





