Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Pagination script v0.1
- * Author: Yasen Georgiev
- * Email: avbincco@gmail.com
- * Web site: http://ygeorgiev.com/
- * License: MIT - http://ygeorgiev.com/licenses/MIT-LICENSE
- */
- $commentsPerPage = 5; // Items per page
- $currentPage = (int)$_GET['p']; // Your pagination's GET parameter
- $getNumRows = mysql_num_rows(mysql_query('SELECT `column` FROM `table`')); // Set your Query to get count of the results in table
- $totalPages = $getNumRows/$commentsPerPage;
- $intvalPages = intval($totalPages);
- $lastPage = ceil($getNumRows / $commentsPerPage);
- $paginationPath = 'page.php?id='.(int)$_GET['id'].'&p='; //Set your URL path
- if($totalPages-$intvalPages>0) {
- $totalPages = $intvalPages+1;
- }
- if($currentPage <= 1 || $currentPage>$totalPages) {
- $start = 0;
- $end = $commentsPerPage;
- $currentPage = "1";
- } else {
- $start = ($currentPage-1)*$commentsPerPage+1;
- $end = $currentPage*$commentsPerPage;
- }
- if($lastPage>1) {
- if($currentPage > 1) {
- $pagesNum .= '<a href="'.$paginationPath.($currentPage-1).'">« Previous page</a> ';
- }
- if($lastPage <= 10) {
- for ($i = 1; $i <= $lastPage; $i++) {
- $pagesNum .= '<a href="'.$paginationPath.$i.'">'.$i.'</a> | ';
- }
- } else {
- if($currentPage <= 5) {
- for($i = 1; $i <= 10; $i++) {
- $pagesNum .= ' | <a href="'.$paginationPath.$i.'">'.$i.'</a> ';
- }
- $pagesNum .= ' | ... | <a href="'.$paginationPath.$lastPage.'">'.$lastPage.'</a> | ';
- } elseif($currentPage > 5 && $currentPage < ($lastPage-5)) {
- $pagesNum .= ' | <a href="'.$paginationPath.'1">1</a> | ... | ';
- for($i = $currentPage-3; $i <= $currentPage+3; $i++) {
- $pagesNum .= '<a href="'.$paginationPath.$i.'">'.$i.'</a> | ';
- }
- $pagesNum .= ' ... | <a href="'.$paginationPath.$lastPage.'">'.$lastPage.'</a> | ';
- } elseif($currentPage >= ($lastPage-5)) {
- $pagesNum .= ' | <a href="'.$paginationPath.'1">1</a> | ... | ';
- if($currentPage < ($lastPage-2)) {
- for($i = $currentPage-3; $i <= $currentPage + 3; $i++) {
- $pagesNum .= '<a href="'.$paginationPath.$i.'">'.$i.'</a> | ';
- }
- } else {
- for($i = $lastPage - 5; $i <= $lastPage; $i++) {
- $pagesNum .= '<a href="'.$paginationPath.$i.'">'.$i.'</a> | ';
- }
- }
- }
- }
- if($currentPage < $lastPage) {
- $pagesNum .= ' <a href="'.$paginationPath.($currentPage+1).'">Next page »</a>';
- }
- $nomeration = str_replace('<a href="'.$paginationPath.$currentPage.'">'.$currentPage.'</a>','<b>'.$currentPage.'</b>',$pagesNum);
- }
- echo $nomeration; //Show the pagination
- ?>
Advertisement
Advertisement