Pagination Class v1.3
Description
This script allows you to easily turn a huge mysql query into multiple pages. It makes the page links and automatically works with just a couple of class calls.
Instructions
1. Include the class above where you are going to use it.
require_once("pagination.php");
2. Set the mysql query equal to the paginated mysql query. The function paginate has 3 inputs, the page you are on (which is he get variable page), the mysql statement and the number of items per page you want. If you leave the number per page blank it defaults to 10.
//start the class
$paging = new paging;
//this grabs all the blog posts
$sql = "SELECT * FROM `blog_posts`";
//set this to the page you want
$currentpage = "5";
//limit the statement to just this page
$new_sql = $paging->paginate($currentpage,$sql);
//now use the new_sql like you normally would...
3. Make the navigation for the pages. The navigation function has 5 inputs, the first 3 are the same as the paginate function, the fourth sets how many page links the navigation shows (It is set to 10 default), and the last sets the local url of the page to add to the link.
//start the class
$paging = new paging;
//this grabs all the blog posts
$sql = "SELECT * FROM `blog_posts`";
//set the current page to the get var page
$currentpage = $_GET['page'];
//limit the statement to just this page
$new_sql = $paging->paginate($currentpage,$sql);
//output the navigation at the top
//we don't have any other get variables so we dont need to set the link
//make sure to use the ORIGINAL sql here, not the new one
echo $paging->navigation($currentpage,$sql);
//now use the new_sql like you normally would...
4. (Optional) Style the navigation.
.pagenav {
padding-left:5px;
padding-right:5px;
height:12px;
font-weight:bold;
}
a .pagenav {
color:#E3BD14;
}
.pageat {
background-color:#cccccc;
}
.paging {
text-align:center;
padding-top:3px;
padding-bottom:2px;
}
#paging {
border:1px solid gray;
background-color:#2f281e;
}
Support
This class is free to distribute as long as it remains free and you keep this message in the distribution. Coded by Oxavi Group, Inc



