Paging prolem

Can anybody help me please, I have been playing around with this script, i have finally managed to get it to work partially. The code returns the results from the database, it shows the first page and calculates all the pages accuratley. the problem is it will only show the results on the first page, even though it shows that there should be more pages. I have an idea why it’s not working, but i am having trouble rectifying the problem. Can somebody please point me in the right direction.

[php]

<?php include 'library/config.php'; include 'library/opendb.php'; $category = $_POST['category'] ; $location = $_POST['location'] ; // how many rows to show per page $rowsPerPage = 10; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT jobtitle, category, location, salary, email FROM vacancies WHERE category='$category' AND location='$location'"; $pagingQuery = "LIMIT $offset, $rowsPerPage"; $result = mysql_query($query . $pagingQuery) or die('Error, query failed'); // print the student info in table echo ''; while(list($jobtitle, $category, $location, $salary, $email) = mysql_fetch_array($result)) { echo ""; } echo '
jobtitle category location salary email
$jobtitle $category $location $salary $email
'; echo '
'; // how many rows we have in database $result = mysql_query($query) or die('Error, query failed'); $numrows = mysql_num_rows($result); // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); $self = $_SERVER['PHP_SELF']; // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // print 'previous' link only if we're not // on page one if ($pageNum > 1) { $page = $pageNum - 1; $prev = " [Prev] "; $first = " [First Page] "; } else { $prev = ' [Prev] '; // we're on page one, don't enable 'previous' link $first = ' [First Page] '; // nor 'first page' link } // print 'next' link only if we're not // on the last page if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " [Next] "; $last = " [Last Page] "; } else { $next = ' [Next] '; // we're on the last page, don't enable 'next' link $last = ' [Last Page] '; // nor 'last page' link } // print the page navigation link echo $first . $prev . " Showing page $pageNum of $maxPage pages " . $next . $last; include 'library/closedb.php'; ?>

[/php]
ADMIN EDIT: Added PHP code tags for readability. Please refer to http://phphelp.com/guidelines.php for posting guidelines.

[php]
// how many rows to show per page
$rowsPerPage = 10;

// by default we show first page
$pageNum = 1;

// if $_GET[‘page’] defined, use it as page number
if(isset($_GET[‘page’]))
{
$pageNum = $_GET[‘page’];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$query = “SELECT jobtitle, category, location, salary, email FROM vacancies WHERE category=’$category’ AND location=’$location’”;

$pagingQuery = “LIMIT $offset, $rowsPerPage”;
$result = mysql_query($query . $pagingQuery) or die(‘Error, query failed’);
[/php]
Correct me if I’m wrong, I might be overlooking something, but your $rowsPerPage never chages which means that your first page will limit 0 to 10 as the $rowsPerPage states, but you do not specify for the $rowsPerPage to go up any which means that your next page will be a limit of 10, 10 instead of 10, 20. Now tell me if you actually did this, b/c I’m not seeing this in the script.

Sponsor our Newsletter | Privacy Policy | Terms of Service