' . $query_row['name'] . '

'; } // If the requested page is less than 1 or more than the total number of pages // redirect to the first page if($pages < 1 || $page > $pages) { header('Location: ?page=1'); // end execution of the rest of this script // it will restart execution after redirection exit; } // If more than one page, show pagination links if($pages > 1) { $html = array(); $html[] = ''; // if you're on a page greater than 1, show a previous link $html[] = (($page > 1) ? 'Previous ' : 'Previous'); // First page link $pageFirst = '1'; $html[] = (($page == 1) ? "{$pageFirst}" : $pageFirst); if ($pages > 6) { $start_cnt = min(max(1, $page - (6 - 1)), $pages - 6); $end_cnt = max(min($pages, $page + 4), 8); $html[] = ($start_cnt > 1) ? '...' : ' '; for ($i = $start_cnt + 1; $i < $end_cnt; $i++) { $html[] = ($i == $page) ? '' . $i . '' : '' . $i . ''; if ($i < $end_cnt - 1) { $html[] = ' '; } } $html []= ($end_cnt < $pages) ? '...' : ' '; } else { $html[] = ' '; for ($i = 2; $i < $pages; $i++) { $html[] = ($i == $page) ? '' . $i . '' : '' . $i . ''; if ($i < $pages) { $html[] = ' '; } } } // last page link $pageLast = '' . $pages . ''; $html[] = (($page == $pages) ? "{$pageLast}" : $pageLast); // Show next page link if you're on a page less than the total number of pages $html[] = ($page < $pages) ? ' Next' : 'Next'; // If you're not on the last page, show a next link $html[] = ''; } else { // show page number 1, no link. $html[] = '1'; } echo implode('', $html);