<?php
include("Paginator.class.php");
//Connect to MYSQL server
mysql_connect("localhost", "root", "");
mysql_select_db("mysql");
//Start getting records
/*
To use this class, you need to set 2 things:
1) The SQL you want to do pagination
2) Items per page
Notes:
- The getTotalPages() function is worked only after you set the SQL.
- Pages start at 1.
- The parameter passed to a funciton should be a non-zero, positive number.
*/
$p = new Paginator();
$p->setSQL("SELECT User FROM user"); //<<< Must set
$p->setItemsPerPage(3); //<<< Must set
print 'The total number of pages is: '.$p->getTotalPages(); print '<br/><br/>';
$result_resources = $p->getPageNumber(1); //<<< Print page 1
printRows($result_resources);
$result_resources = $p->getPageNumber(2); //<<< Print page 2
printRows($result_resources);
$result_resources = $p->getPageNumber(3); //<<< Print page 3
printRows($result_resources);
$result_resources = $p->getPageNumber(4); //<<< Print page 4
printRows($result_resources);
$result_resources = $p->getPageNumber(5); //<<< Print page 5
printRows($result_resources);
function printRows($res){
while($row = mysql_fetch_object($res)){
print $row->User.'<br/>';
}
}
?>
|