Pagination Problems
Posted: Sat Apr 10, 2010 12:31 pm
Hi im having a prblem with my pagination most of it seems to work yet when i wanted to add a forward and back button and put a check in to stop it going past the amount of results that qwas returned by the it wouldnt work heres my code im pretty sure its probably a stupid little thing but i cant seem to find it
this bit is for the actuall checking to get the results and restricting the page numbers and these next parts are for the actual links to cycle back and forth the pages
if you could maybe point me to some resources that could help me see where i have gone wrong in my logic or w/e that would be much appreciated thanks
Code: Select all
<?PHP
//start the session
session_start();
//check to make sure the session variable isn't registered
if(!session_is_registered('EmpID')){
//the session variable isn't registered, send them back to the login page
header( "Location: JMSystemLogin.php" );
}
$EmpID = $_SESSION['EmpID'];
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="password1"; // Mysql password
$db_name="JMSystemDB"; // Database nam
mysql_connect($host,$username,$password) or die("ERROR:".mysql_error());
mysql_select_db($db_name) or die("ERROR DB:".mysql_error());
$next = 1;
$prev = 1;
if(!isset($_GET['offset']))
{
$offset = 0;
$prev = 0;
}
elseif(isset($_GET['offset']))
{
$offset = $_GET['offset'];
$record = $_GET['record'];
if(record == 'next')
{
$offset++;
}
if(record == 'prev')
{
$offset--;
}
if($offset == 0)
{
$prev = 0;
}
}
else
{
echo 'error1';
}
$query = "SELECT * FROM Job WHERE Employee_EmployeeID = '$EmpID' AND Fixed = 0 ORDER BY TargetDate LIMIT $offset,1";
$result = mysql_query($query);
while($r = mysql_fetch_array($result))
{
$JobID = $r['JobID'];
$Unit = $r['Units_UnitID'];
$Desc = $r['JobDescription'];
$OpenedBy = $r['JobOpendBy'];
$Target = $r['TargetDate'];
$Comments = $r['Comments'];
}
$chknext = $offset + 1;
$query_chk = "SELECT * FROM Job WHERE Employee_EmployeeID = '$EmpID' AND Fixed = 0 ORDER BY TargetDate LIMIT $chknext,1";
$result_chk = mysql_query($query_chk);
if(!$result_chk)
{
$next = 0;
}
?>Code: Select all
<?PHP if(prev == 1) { ?><a href="Jobs.php?offset=<?PHP echo $offset ?>&record=prev">previous record</a> <?PHP } ?><br />
<?PHP if(next == 1) { ?><a href="Jobs.php?offset=<?PHP echo $offset ?>&record=next">next record</a><?PHP } ?>