PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
<?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;
}
?>
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
that seemed to get the link showing for the next page but it still doesnt actually take me to the next record i have checked to make sure there is more than one record in the db just in case and there is. here is the changed version of that link code though.