Hi There,
I in fact got a paging system ready to use now. it works great. Maybe it is something you are looking for.
But i also got a question to improve it.
As a result, when i got about 13 pages to show it will show you the following:
[First Page][Prev][1][2][3][4][5][6][7][8][9][10][11][12][13][Next][Last Page]
But i would realy like it to show a limit of 10 pages at a time, so when i get to page 7 or at least further then page 2 it shows
[First Page][Prev][3][4][5][6][7][8][9][10][11][12][Next][Last Page]
Does anyone know how to do that? I'm not really a very good with php (and dutch;) so please do not get to technical on this.
- <?php
-
-
$pageNum = 1;
-
if (empty($page)){
-
$page=1;
-
}
-
else{
-
$page = (int) $page;
-
}
-
-
if(isset($_GET['page']))
-
{
-
$pageNum = $_GET['page'];
-
}
-
-
if(!isset($_GET['category_id'])){
-
-
}
-
else{
-
$id = (int) $_GET['category_id'];
-
}
-
-
$offset = ($pageNum - 1) * $rowsPerPage;
-
-
-
-
$query = "SELECT id FROM fotos WHERE session_id='$id' LIMIT $offset, $rowsPerPage";
-
$result = mysql_query($query) or die('Error, query failed');
-
-
-
-
-
// how many rows we have in database
-
$query = "SELECT COUNT(id) AS numrows FROM fotos WHERE session_id='$id'";
-
$result = mysql_query($query) or die('Error, query failed');
-
$row = mysql_fetch_array($result, MYSQL_ASSOC);
-
$numrows = $row['numrows'];
-
-
// how many pages we have when using paging?
-
$maxPage = ceil($numrows/$rowsPerPage);
-
$offset_prev = (($pageNum - 1) * $rowsPerPage)- $rowsPerPage;
-
$offset_next = (($pageNum + 1) * $rowsPerPage)- $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
-
{
-
$offset_nav = ($page * $rowsPerPage) - $rowsPerPage;
-
$nav .= " <a href=\"$self?page=$page&category_id=$id&offset=$offset_nav\">$page</a> ";
-
}
-
}
-
-
// creating previous and next link
-
// plus the link to go straight to
-
// the first and last page
-
-
if ($pageNum > 1)
-
{
-
$page = $pageNum - 1;
-
$prev = " <a href=\"$self?page=$page&category_id=$id&offset=$offset_prev\">[Prev]</a> ";
-
-
$first = " <a href=\"$self?page=1&category_id=$id&offset=0\">[First Page]</a> ";
-
}
-
else
-
{
-
$prev = ' '; // we're on page one, don't print previous link
-
$first = ' '; // nor the first page link
-
}
-
-
if ($pageNum < $maxPage)
-
{
-
$offset_max = ($maxPage * $rowsPerPage) - $rowsPerPage;
-
$page = $pageNum + 1;
-
$next = " <a href=\"$self?page=$page&category_id=$id&offset=$offset_next\">[Next]</a> ";
-
-
$last = " <a href=\"$self?page=$maxPage&category_id=$id&offset=$offset_max\">[Last Page]</a> ";
-
}
-
else
-
{
-
$next = ' '; // we're on the last page, don't print next link
-
$last = ' '; // nor the last page link
-
}
-
-
// print the navigation link
-
echo $first . $prev . $nav . $next . $last;
-
-
-
// and close the database connection
-
include '../library/closedb.php';
-
?>