Ok i'm in a pickle now.
i have the results from my query returning a limited number of rows and the prev and next links in place , now the problem i am now faced with is that my next link will not show the next set of 3 results , it tells me that there are no results . I can't get it to see beyond the first 3 results.
below i have pasted my code,
<?
//connect to server and select database
$conn = mysql_connect("hostname", "user_name", "password")
or die(mysql_error());
mysql_select_db("database_name",$conn) or die(mysql_error());
//choose the amount of stats you want to display in one page
$per_page = 3;
/original code // retrieve data from database
$sql_text = "SELECT FROM jobs";*/
//create and issue the query
$sql_text = "SELECT *
FROM jobs
WHERE division = '".$_GET['division']."'
ORDER BY job_type";
if(!isset($GET['page'])){
$page = 1;
}else{
$page = $GET['page'];
}
//set up the variables for the prev and next links
$prev_page = $page - 1;
$next_page = $page + 1;
//get the data from the database
$query = mysql_query($sql_text);
/set up specified page, so we have set $per_page to 3 we need to figure out the starting page based on the amount of data recieved from the database. mysql_num_rows() will get the no. of rows in the result from our mysql_query/
$page_start = ($per_page * $page) - $per_page;
$num_rows = mysql_num_rows($query);
if ($num_rows <= $per_page){
$num_pages = 1;
}elseif (($num_rows % $per_page) == 0) {
$num_pages = ($num_rows / $per_page);
}else{
$num_pages = ($num_rows / $per_page) + 1;
}
$num_pages = (int) $num_pages;
if ($page > $num_pages || $page < 0) {
echo 'You have specified an invalid page number'
;}
$sql_text = $sql_text." LIMIT $page_start, $per_page";
$query = mysql_query($sql_text);
?>
<html>
<head>
<title>Top Secretaries</title>
</head>
<body>
<p>There are currently <? echo "$num_rows"; ?> files in this section</p>
<?
// previous link. we need a if statement to determine if prev page is not equal to 0, then echo the url for the link
if ($prev_page != 0){
echo '<a href="job_listing2.php?page='.$prev_page.'">prev</a> |';
}
//displays the next link
if ($page != $num_pages) {
echo '|<a href="job_listing2.php?page='.$next_page.'">Next</a>';
}
?>
<?php // This calls the data to be displayed.
while ($info = mysql_fetch_assoc($query)) {
echo("<p>\n"
. "<b>job ref:</b> " . $info["job_ref"] . "<br />\n"
. "<b>job title:</b> " . $info["job_title"] . "<br />\n"
. "<b>job type:</b> " . $info["job_type"] . "<br />\n"
. "<b>location:</b> " . $info["location"] . "<br />\n"
. "<b>contact:</b>\n"
."<a href=\"".$info["contact"] . "\">".$info["contact"] ."</a><br />\n");
echo("</p>\n");
echo("<hr style=\"color:black;width:500px;text-align:left;\">\n\n\n\n");
}
?>
</body>
</html>