Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.
Popular code excerpts may be moved to "Code Snippets" by the moderators.
This class pager is for large number of records from the database and you want to divide it for example 5 records per page. it is easy to navigate your page.
$sql = "SELECT * FROM tbl_data";
// 2nd parameter is the number of record per page
$pager = new Pager($sql, 4, $_GET['page']);
while($row = $pager->fetchObject())
{
echo $row->firstname;
echo "<BR>";
}
echo $pager->getPageNav();
Also remove the private methods which are called only once, none of their callers is longer than a "hand" so there's no need to split them.
There are improperly named methods -- do you way in Englih "get total record" or "get total records" or even "get records count".
You don't seem to check if the user-specified page is outside the available records.
Agreed, the query needs a LIMIT. For large data sets this is a must. Also, when you switch to LIMIT, don't use SQL_CALC_FOUND_ROWS to figure out how many pages of data you'll have. Use simple previous and next links. Your database will thank you for it.