PCHomepage
Programmer
Using a simple page navigator that gives basic Page navigation to build the LIMIT clause dynamically seems to give unexpected results. For example, limiting results to 20 records but having a record set containing 23 records, when I select Page 2, it is empty but when I select Page 1 again, there the last three are.
The HTML navigator is something like this with the current page in-linked in square brackets:
. . . and the PHP building the conditional to append to the end of the query is:
I see what it's doing - for Page 2 it is giving LIMIT 41, 20 and worked it out so that it works and gives the proper LIMIT 21, 20 but it seems cumbersome so I'm wondering if there is a better way:
The HTML navigator is something like this with the current page in-linked in square brackets:
Code:
<div class="Pagination">[1]
<a href="/categories/help/sitesearch.php?Page=2" title="To page 2">2</a></div>
. . . and the PHP building the conditional to append to the end of the query is:
Code:
if ($_GET['Page']) :
$Offset = (20 * $_GET['Page']) + 1;
$Query .= " LIMIT $Offset, 20";
else:
$Query .= " LIMIT 0, 20";
endif;
I see what it's doing - for Page 2 it is giving LIMIT 41, 20 and worked it out so that it works and gives the proper LIMIT 21, 20 but it seems cumbersome so I'm wondering if there is a better way:
Code:
if ($_GET['Page']) :
$Offset = (20 * $_GET['Page']) - 19;
$Query .= " LIMIT $Offset, 20";
else:
$Query .= " LIMIT 0, 20";
endif;