Hi I have setup a nice little paging system to allow the page numbers to be displayed.
The problem is I want to be able to show 10 pages at a time i.e. page 1.....10 then when page 2 is clicked it shows 2.....11 etc etc, does anyone know how to do this or is there a simple way I could add this to my code below.
The problem is I want to be able to show 10 pages at a time i.e. page 1.....10 then when page 2 is clicked it shows 2.....11 etc etc, does anyone know how to do this or is there a simple way I could add this to my code below.
Code:
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 10;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
$getresults = mysql_query("select `id`,`title`,`introtext`,`fulltext`,`created` from `mos_content` where `sectionid` = '2' and `state` ='1'");
$total_results = mysql_num_rows($getresults);
$total_pages = ceil($total_results / $max_results);
$pagination = '';
$news = mysql_query("select * from table where whatever LIMIT $from, $max_results");
while ($i = mysql_fetch_row($news))
{
echo "Whatever the results are";
}
/* Create a PREV link if there is one */
if($page > 1)
{
$pagination .= '<a href="news.php?page='.$prev.'">Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i.' ';
}
else
{
$pagination .= '<a href="news.php?page='.$i.'">'.$i.'</a> ';
}
}
/* Print NEXT link if there is one */