// how many rows we have in database
$query = "SELECT * FROM news";
$result2 = mysqli_query($query) or die('Error, query failed');
$numrows = mysqli_num_rows($result2);
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " $page ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
//$showmore = " more news ";
$prev = " [Prev] ";
$first = " [First Page] ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
//$showmore = " more news ";
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " [Next] ";
$last = " [Last Page] ";
//$showmore = " more news ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
//$showmore = " more news ";
}
// print the navigation link
echo $first . $prev . $nav . $next . $last ;
?>