function pagination($item_count, $limit, $cur_page, $link) ( $page_count = ceil($item_count/$limit); $current_range = array(($cur_page-2 $page_count ? $page_count : $cur_page+2)); // First and Last pages $first_page = $cur_page > 3 ? '1'.($cur_page < 5 ? ', ' : '… ') : null; $last_page = $cur_page $page_count-4 ? ', ' : '… ').''.$page_count.'' : null; // Previous and next page $previous_page = $cur_page > 1 ? 'Previous | ' : null; $next_page = $cur_page < $page_count ? ' | Next' : null; // Display pages that are in range for ($x=$current_range(0);$x <= $current_range(1); ++$x) $pages() = ''.($x == $cur_page ? ''.$x.'' : $x).''; if ($page_count > 1) return '
Pages: '.$previous_page.$first_page.implode(', ', $pages).$last_page.$next_page.'
'; )
Kullanım:
pagination( total amount of item/rows/whatever, limit of items per page, current page number, url );
Misal:
pagination(45, 20, 1, 'http://example.com/userlist/%d.html');
Çıktı HTML:
Pages: 1, 2, 3 | Next