PHP pagination class
PHP pagination class for displaying database results in pages
Usage
Simple and raw. No theory, plain code. This is it, PHP pagination class, one of the most wanted snippets for web applications.
How to use it:
Istantiate the class (PHP5 version):
$p = new pagination();
Run the first query to select the number of total rows and call the first function,
with arguments the total rows number, how many rows to show per page and current page number:
$arr = $p->calculate_pages(70, 10, 1);
This function will call the second one in the class to get the surrounding pages of the page
we are requesting.
The returned result should look like this:
Array
(
[limit] => LIMIT 0,10
[current] => 1
[previous] => 1
[next] => 2
[last] => 7
[info] => Page (1 of 7)
[pages] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
)
Take care.

Comments
Really,Excellent piece of code! i think it provide a new platform 4 php developer.
Great php class. Works just fine!
i think, something is missing with this.
test this but it give error like ERROR: "Fatal error: Cannot pass parameter 3 by reference on line $arr = $p->calculate_pages( $result, 10, 1 );"
Really thanks!. I used for my client site.
Regards
Munir
err.. Where is the result array that is used to loop the data to display on each page?? Am I missing something?
Great class. Thanks. It was very easy to implement it to my site.
Can you give an example page using this class?
I tested it using this code below but I got this
ERROR: "Fatal error: Cannot pass parameter 3 by reference on line $arr = $p->calculate_pages( $result, 10, 1 );"
How to resolve this? ;)
<?php
require_once( 'classes/connection.php' );
require_once( 'classes/php-pagination-class.php' );
$p = new pagination();
$qry = mysql_query( "SELECT * FROM items" );
$result = mysql_num_rows( $qry );
$arr = $p->calculate_pages( $result, 10, 1 );
echo "";
echo print_r( $arr );
echo "";
?>
Excellent piece of code!
I've altered the public function to reach for the get_surrounding_pages to set the $show from a public call :)
It's the class instantiator function for PHP5.
It is executed when you do $foo = new bar();
can you tell me why do you have this line?
public function __construct()
{
}
Thanks a bunch, very useful.
Used this today. It's great Steve!