Hi All
Ive had this nagging problem for the last couple of weeks.
Im trying to set up some pagination. Most of the code works in that displays the number of results i ask, the number of pages etc. BUt when you click on the next link, the page doesnt produce no errors and just says that are no jobs matching your criteria.
There is 3 parts of to the code, COULD SOMEONE PLEASE HELP ME? part 3 code is the where links are displayed.
part 1
DB connection info goes here
if (!($_GET['limit'])){
$limit = 1;} // Default results per-page.
if (!($_GET['page'])){
$page = 0;} // Default page value.
$numresults = mysql_query("select * from $table_name where job_sector = '$POST[job_sector]' AND region = '$POST[region]'"); // the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows % $limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
?>
part 2
<?
// Now we can display results.
$results = mysql_query("select * from $table_name where job_sector = '$POST[job_sector]' AND region = '$POST[region]' ORDER BY date_posted ASC LIMIT $page,$limit"); // the query.
while ($row = mysql_fetch_array($results))
{
$candidate_id = $row['candidate_id'];
$what_they_do = stripslashes($row['what_they_do']);
$contact_phone = $row['contact_phone'];
$contact_name = $row['contact_name'];
$contact_email = $row['contact_email'];
$date_posted = $row['date_posted'];
$job_title = stripslashes($row['job_title']);
$candidate_description = stripslashes($row['cand_description']);
$short_summary = substr($candidate_description,0,150);
$location = stripslashes($row['location']);
$salary = $row['salary'];
$display_block .= "
<table width=80% border=0 cellspacing=1 cellpadding=0>
<tr bgcolor=#FFEBD7>
<td><a href=candidate_detail.php?candidate_id=$candidate_id>$what_they_do</a><br>$short_summary....<a href=candidate_detail.php?candidate_id=$candidate_id>[More]</a><br><strong>Anticipated Salary:</strong> $salary
</td>
<td width=26% valign=top>$location</td>
</tr>
</table>";
}
if ($numrows == 1){
echo ("<strong>$numrows</strong> candidate matched your search criteria");
}else{
echo ("<strong>$numrows</strong> candidates matched your search criteria");
}
if ($numrows == 0){
echo ("<br><a href='#' onclick='history.back();'>Click here to try a new search</a>");
}
?>
part 3
<?
$job_sector = $POST['job_sector'];
$region = $POST['region'];
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?job_sector=$job_sector®ion=$region&page=$back_page&limit=$limit\">back</a> \n");}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"$PHP_SELF?job_sector=$job_sector®ion=$region&page=$ppage&limit=$limit\">$i</a> \n");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"$PHP_SELF?job_sector=$job_sector®ion=$region&page=$next_page&limit=$limit\">next</a>");}
?>