I'm trying to use a "previous" and "next" button to return one record at a time ordered by ID. I'm having some issues with the code though.
<?php
include ('header.php');
include ('connection.php');
//pagination starts here
if(isset($_GET['page'])){
$page = preg_replace('#[^0-9]#','',$_GET['page']);
}else{
$page = 1;
}
$perPage = 1;
$lastPage = cell($count / $perPage);
if($page < 1){
$page = 1;
}else if($page > $lastPage){
$page = $lastPage;
}
$limit = 'LIMIT ' .($page -1)*$perPage .',$perPage';
$query = mysql_query('SELECT LastName FROM residents ORDER BY ID DESC $limit');
if($lastPage != 1){
if($page != $lastPage){
$next = $page + 1;
$pagination.='<a href="AutoIncrement.php?page='.$next.">Next</a>';
}
//error occurs here
if($page != 1){
$prev = $page - 1;
$pagination.='<a href="AutoIncrement.php?page='.$prev.">Previous</a>';
}
}
?>
It all seems to be ok except I keep getting an error for the last IF statement. Any thoughts?