I have a pagination script which works. The first page has a 'next' link, the last page should have a 'previous' link and the ones in between have both. The problem is that the last page doesnt show it 'previous' link.
Heres the code
include '../inc/connect.php';
//paganation settings
$per_page = 2;
$pages_query = mysqli_query($link, "SELECT COUNT(`id`) FROM `gallery`") or
die(mysqli_error($link));
$result = mysqli_fetch_array($pages_query, MYSQLI_NUM);
$pages = $result[0] / $per_page;
$page = (isset($_GET['page']) AND (int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$last = ($pages - 1) / $per_page;
$prev = $page - 1;
$next = $page + 1;
//query the db
$q =mysqli_query($link, "SELECT * FROM gallery
ORDER BY id DESC
LIMIT $start, $per_page");
//find out the page we are on and display next and previous links accordingly
if ($page >= 1 && $page < $pages){
echo "<span class='next'>";
echo "<a href=\"?page={$next}\">Next page</a> ";
echo "</span>";
if ($page >=2){
echo "<span class='prev'>";
echo "<a href=\"?page={$prev}\">Previous page</a> ";
echo "</span>";
}
}
else if ($page > $pages + 1){
echo 'No more images in the database';
}
//display images
while($row=mysqli_fetch_array($q)){
echo "<a href='{$row['filename']}' rel='thumbnail'>
<img class='nailthumb-container' src='{$row['filename']}'
alt='{$row['description']}.Image' title='{$row['description']}' />
</a>";
}