I would like to add pagination to a page that renders dynamic data. But I get the following erros when I click the page links(1,2,3, etc). I am fairly new to php, please assist.
Notice: Undefined index: Jobid in C:\wamp\www\HR\HR_Applicants.php on line 4 Notice: Undefined index: Jobid in C:\wamp\www\HR\HR_Applicants.php on line 8 Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\HR\HR_Applicants.php on line 18 Notice: Use of undefined constant mysql_error - assumed 'mysql_error' in C:\wamp\www\HR\HR_Applicants.php on line 28
All the errors following the error on line 4 Occurs because Jobid loses its value when I click on the pagination link(i.e 1, 2, 3, etc). Initially when the page load, it land on the normal(unpaginated page) and that works fine. Problems arises when the pagination links are clicked.
Here follows the code for the paginated page.
<?php
session_start();
print_r( $_GET, true );
print_r($_REQUEST['Jobid']);
require 'scripts/connect.php';
//Get the Person's jobid
$jobid = $_GET['Jobid'];
//the number of rows to show per page
$per_page = 2;
//Count the number of items in the database
$pages_query = mysql_query("SELECT COUNT('Personid') FROM person where jobid=$jobid");
//Round the number of pages to the nearest 10
$pages = ceil(mysql_result($pages_query,0) / $per_page);
//Check if there value of page is set
$page = (isset($_GET['page'])) ?(int)$_GET['page']: 1;
//Start counting from zero
$start = ($page -1)* $per_page;
//Select the data from the datbase, but limit it to the number of item per page
$Personid_query ="SELECT * FROM person where jobid=$jobid LIMIT $start ,$per_page";
$Personid = mysql_query($Personid_query) or die(mysql_error);
$row = mysql_fetch_assoc($Personid);
?>
The above code is right on top, just before the HTML tags. The following code falls within the HTML tags because the data displayed to user is dynamic and its selected from the database where the 'jobid' is found.
<fieldset>
<?php do{?>
<p><a href="Resume.php?Personid=<?php echo $row['Personid'];?>"><?php echo $row['Personid']?></a></p>
<?php echo $row['Title'];?> <?php echo $row['Forename']?> <?php echo $row['Surname']?> <?php echo $row['ApplicationDate'];?>
<?php }while ($row = mysql_fetch_assoc($Personid))?>
<br />
<?php
//Show the pagination links at the bottom of the page
if ($pages >= 1 && $page<= $pages)
{
for($i=1;$i<=$pages;$i++)
{
echo '<a href="?page='.$i.'">'.$i.'</a> ';
}
}
?>
</fieldset>