$no_results = TRUE; // No results found yet
$howmany = 6; // Return 10 results per query
// Set default starting point of query to 0, or, if set, to $_GET['rs']
$row_start = (isset($_GET['rs'])) ? $_GET['rs'] : 0;
// Do our SQL query, with something like LIMIT 0, 10
$sql = "SELECT SQL_CALC_FOUND_ROWS id, title, link, image, value, value2, description FROM offers WHERE categoryID='$cat' ORDER BY `id` DESC LIMIT ". $row_start .", ". $howmany ."";
$result = mysql_query($sql);
// Get the number of rows that would have been returned WITHOUT a limit clause, to be used later for paging.
$count_sql = "SELECT FOUND_ROWS() AS total";
$count_sql_result = mysql_query($count_sql);
$count_row = mysql_fetch_array($count_sql_result);
$count_result = $count_row['total'];
// Start looping through our result set
while($row = mysql_fetch_array($result)) {
$no_results = FALSE;
// Save results of query to $line_output
$line_output .= "
// Don't bother building paging if we don't have records
if ($no_results) {
$line_output = "No records found...";
$page_output = "";
}
else {
// Build <prev> and <next> links and save to $page_output
$rs_prev = $row_start - $howmany; // where would prev page start, given current start less no. of records
$rs_next = $row_start + $howmany; // where would next page start, given current start plus no. of records
// If for some reason the next <prev> starting point is negative, do not display <prev>
// This happens when our current starting point is already 0
// This may happen if some smartass manually changes the rs= bit in the url
$page_output_prev = ($rs_prev < 0) ? "" : "<div id=\"next\"><a href='?layouts=".$cat."&rs=".$rs_prev."'>Previous</a></div>";
// Will the next page jump start point exceed the number of records returned?
// If so, don't display <next>'
$page_output_next = ($rs_next >= $count_result) ? "" : "<div id=\"next\"><a href='?layouts=".$cat."&rs=".$rs_next."'>Next</a></div>";
// Just something to put between <prev> & <next>, IF they are both active
if (($page_output_prev == "") || ($page_output_next == "")) {$page_output_breaker = "";}
else { $page_output_breaker = " || ";}
Ahhh, Thanks I missed that. For some reason I can't get the prev/next links to show however if you go to /offers.php?offers=11&rs=2 the pagination works fine. :S