Hi
Ive got a problem with the following code, im trying to pagination on one of my webpages but the page comes out blank. Any ideas or tell me where im going wrong?
<?
$db_name = "web";
$table_name = "candidates";
$connection = mysql_connect("", "", "") or die(mysql_error());
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
if (!($limit)){
$limit = 10;} // Default results per-page.
if (!($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.
if ($numrows == 0){
echo "There are no candidates matching your criteria";
echo "<a href='#' onclick='history.back();'><br><br>Try a new search</a>"; // bah, modify the "Not Found" error for your needs.
}else{
"$display_block";
}
$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.
?>
</div></td>
<td height="18" align="center" valign="top"> </td>
</tr>
<tr>
<td valign="top"> </td>
<td valign="top"> </td>
<td align="center" valign="top"> </td>
<td height="84" align="center" valign="top">
<div align="left">
<table width="79%" border="0">
<tr>
<td width="50%" align="left">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
</td>
<td width="50%" align="right">
Page <b><?=$current?></b> of <b><?=$total?></b>
</td>
</tr>
<tr>
<td colspan="2" align="right">
</td>
</tr>
<tr>
<td colspan="2" align="right">
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a>
</td>
</tr>
</table>
<?
// Now we can display results.
$results = mysql_query= ("select * from $table_name where job_sector = '$POST[job_sector]' AND region = '$POST[region]'"); // the query.
while ($row = mysql_fetch_array($result))
{
$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 ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&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?query=$query&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?query=$query&page=$next_page&limit=$limit\">next</a>");}
?>