There are a few reasons that you might want to spit a query into multiple pages. The main reasons are to break up lots of data to make it easier to see, or to speed up big queries by limiting the results to a certain amount. When I coded class.pagination.php I wanted to make sure that it would be easy to skin as well as work with mod-rewrite. More importantly it had to work with complex pages that used an unlimited amount of join statements.
Here is a simple example. Make sure that you put the noted CSS classes in your style sheet. Say you want to break up a query on index.php?module=users. You can do use it like this:
[CODE]
require_once(”class.pagination.php“);
/* figure out what the link is for later */
$pagelink = “index.php?module=users”;
/* include class */
require_once(”../include/pages.class.php”);
/* get the page */
$page = $_GET[page];
if(!$page){ $page = 1; }
/* initialize variables */
$pageObject = new Pagination;
$pageObject->current_page = $page;
$pageObject->num_per_page = “50″;
$pageObject->link = $pagelink;
/*
* set up count query
*
* note that this is similar to your main query
*
*/
$countquery = “SELECT COUNT(ID) FROM users WHERE authority = ’staff’”;
/* count how many pages */
$count = $pageObject->getCount($countquery);
/* get limit clause for main query */
$limitsql = $pageObject->getLimits($count);
/* get pagination navigation to print at end */
$pagenav = $pageObject->getNavigation($count);
$mainquery = “SELECT * FROM users WHERE authority = ’staff’ “. $limitsql;
$data = mysql_query($mainquery);
while($row=mysql_fetch_array($data)){
//do something here
}
/* echo out the menu */
echo $pagenav;
[/CODE]
Code | No Comments »