My first pagination class
Posted: Thu Nov 18, 2004 5:39 pm
Hi All,
I have written a pagination class but just need someone to check that I am doing this right. My aim is to set up the class so that I can create a new pagination object and give it variables in the same line. So I made a class called pagination with a function inside it called pagination that takes some variables. Is this the right way to do it? It seems to work.
I create it and pass some variables to it by using the following code:
$pagination = new pagination(12,6,1);
echo $pagination->numPages;
The echo was just to check that it was working ok.
Brad.
I have written a pagination class but just need someone to check that I am doing this right. My aim is to set up the class so that I can create a new pagination object and give it variables in the same line. So I made a class called pagination with a function inside it called pagination that takes some variables. Is this the right way to do it? It seems to work.
Code: Select all
<?
//Set up pagination Class
class pagination {
var $first;
var $last;
var $total;
var $limit;
var $page;
var $numPages;
function pagination($total, $limit, $page) {
$this->total = (int) $total;
$this->limit = max((int) $limit, 1);
$this->page = (int) $page;
$this->numPages = ceil($total / $limit);
$this->page = max($page, 1);
$this->page = min($page, $this->numPages);
$this->first = ($page - 1) * $limit;
$this->last = min((int)$this->first+$this->limit, $this->total);
}
}
?>I create it and pass some variables to it by using the following code:
$pagination = new pagination(12,6,1);
echo $pagination->numPages;
The echo was just to check that it was working ok.
Brad.