I can remember years ago when I first began coding in PHP and MySQL, how excited I was the first time I got information from a database to show up in a web browser. For someone who had little database and programming knowledge, seeing those table rows show up onscreen based on the code I wrote (okay so I copied an example from a book — let's not split hairs) gave me a triumphant high. I may not have fully understood all the magic at work back then, but that first success spurred me on to bigger and better projects.
While my level of exuberance over databases may not be the same as it once was,
ever since my first 'hello world' encounter with PHP and MySQL I've been hooked
on the power of making things simple and easy to use. As a developer, one problem
I'm constantly faced with is taking a large set of information and making it easy
to digest. Whether its a large company's client list or a personal mp3 catalog,
having to sit and stare at rows upon rows upon rows of data can be discouraging
and frustrating. What can a good developer do? Paginate!
Pagination
Pagination is essentially the process of taking a set of results and spreading
them out over pages to make them easier to view.

I realized early on that if I had 5000 rows of information to display not only
would it be a headache for someone to try and read, but most browsers would take
an Internet eternity (i.e. more than about five seconds) to display it. To solve
this I would code various SQL statements to pull out chunks of data, and if I was
in a good mood I might even throw in a couple of "next" and "previous" buttons.
After a while, having to drop this code into every similar project and customize
it to fit got old. Fast. And as every good developer knows, laziness breeds inventiveness
or something like that. So one day I sat down and decided to come up with a simple,
flexible, and easy to use PHP class that would automatically do the dirty work for
me.
A quick word about me and PHP classes. I'm no object-oriented whiz. In fact I hardly
ever use the stuff. But after reading some OOP examples and tutorials, and some
simple trial and error examples, I decided to give it a whirl and you know what?
It works perfectly for pagination. The code used here is written in PHP 4 but will
work in PHP 5.
The Database
Gotta love MySQL. No offense to the other database systems out there, but for
me all I need is MySQL. And one great feature of MySQL is that they give you some
free sample databases to play with at
http://dev.mysql.com/doc/#sampledb.
For my examples I'll be using the world database (~90k zipped) which contains over
4000 records to play with, but the beauty of the PHP script we'll be creating is
that it can be used with any database. Now I think we can all agree that if we decided
not to paginate our results that we would end up with some very long and unwieldy
results like the following:

(click for full size, ridiculously long image ~ 338k)
So lets gets down to breaking up our data into easy to digest bites like this:

Beautiful isn't it? Once you drop the pagination class into your code you can
quickly and easily transform a huge set of data into easy to navigate pages with
just a few lines of code. Really.
Paginator.class.php
Our examples will use just two scripts: paginator.class.php, the reusable
pagination script, and index.php, the PHP page that will call and use
paginator.class.php. Let's take a look at the guts of the pagination class
script.
<?php
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp = 25;
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 7;
$this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
}
function paginate()
{
if($_GET['ipp'] == 'All')
{
$this->num_pages = ceil($this->items_total/$this->default_ipp);
$this->items_per_page = $this->default_ipp;
}
else
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
}
$this->current_page = (int) $_GET['page']; // must be numeric > 0
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($this->num_pages > 10)
{
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
// loop through all pages. if first, last, or in range, display
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All')) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
$this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All\">All</a> \n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page\">$i</a> ";
}
$this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All\">All</a> \n";
}
$this->low = ($this->current_page-1) * $this->items_per_page;
$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_items_per_page()
{
$items = '';
$ipp_array = array(10,25,50,100,'All');
foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value;return false\">$items</select>\n";
}
function display_jump_menu()
{
for($i=1;$i<=$this->num_pages;$i++)
{
$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
}
return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page';return false\">$option</select>\n";
}
function display_pages()
{
return $this->return;
}
}
?>
Phew, that's a lot of code! But don't worry, I'll explain what all the
different parts do and how they're used.
Have a Little Class
Let's begin at the beginning. First off we declare the class and give it a
name. Paginator should do it. And while we're at it, let's set some variables,
or properties in OOP speak, that our new paginator object will use.
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp = 25;
We start off our class by giving it a name, in this case "Paginator", and
defining the variables (a.k.a the properties of an object) that we'll be using.
When we create a new object using this class (a.k.a instantiating), the object
will have these properties and one of them, $default_ipp (the default number of
items per page), is also initialized to a value of 25.
Our class will have five methods, or
member functions, which do the heavy lifting; and they're named Paginator, paginate,
display_items_per_page, display_jump_menu, and display_pages.
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 7;
$this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
}
The Paginator function is also referred to as our constructor method, which just means when you
create a new paginator object, this function is also called by default. When we instantiate a new paginator
object, this initializes it with some default values. Here we set those
variables and check to see if we've changed the number of items per page to
display. If the items per page variable isn't set in the URL's query string ($_GET['ipp']),
we use the default number when the class was created.
The next method, the paginate function, is the Arnold Schwarzenegger, the Jean Claude Van Damme, the
meat of our class. The paginate method is what determines how many page
numbers to display, figures out how they should be linked, and applies CSS
for styling.
if($_GET['ipp'] == 'All')
{
$this->num_pages = ceil($this->items_total/$this->default_ipp);
$this->items_per_page = $this->default_ipp;
}
else
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
}
The first part of this method determines the number of pages we'll be
outputting and sets the number of items per page. First it tests to see if we
want to display all the items on one page. If so, it simply displays all the
items on one page and if not, it calculates the number of links it will need to
output, based on the number of items per page and the total number of items. It
also throws in some error checking to make sure that the number of items per
page is a numeric value.
$this->current_page = (int) $_GET['page']; // must be numeric > 0 if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1; if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages; $prev_page = $this->current_page-1; $next_page = $this->current_page+1;
The next part gets the page number we're on and checks to make sure that it's
a number in a valid range. It also sets the previous and next page links.
The rest of the paginate method is what does all the hard work. We check to
see if we have more than ten pages (if($this->num_pages > 10)), ten
being a number that you can easily change. If
we don't have more than ten pages, we simply loop from one to however many pages
we do have, and link them up accordingly. We don't display any previous page or next page
links since we're displaying all page numbers and this would be a bit redundant, but
we do display a link to all items. If we have more than ten pages, then
instead of displaying links to each and every page (if we had say 200 pages to
display, things might get a little ugly), we display links to the first and last
page and then a range of pages around the current page that we're on. This is
where the variable (property) $this->mid_range comes into play. This variable tells the
paginator how many page numbers to display between the first and last pages. By
default this is set to seven, however you can change it to anything you like.
Just a note, the mid range value should be an odd number so the display is
symmetrical, but it can be even if you like. For example, let's say we have 4000
rows of data in all, and we're viewing 50 rows of data per page. That gives us
79 pages to display, but aside from the first and last pages we're
only going to display links to three pages above and below the page we're on. So
if we're on page 29, the paginator will display links to page 1, 26, 27, 28, 29,
30, 31, 32, and 79 (don't worry, if you want to jump to a specific page not in
that range I'll explain how to do that a little later on). As you move
closer to the upper and lower page limits, the mid range adjusts itself so that
you always have at least the number of page links that mid_range is set for.
The next method, display_items_per_page, is an optional method that will display a drop
down menu that allows a visitor to change the number of items displayed per
page. The default values for the drop down menu are 10, 25, 50, 100, and
All. You can change the numeric values to anything you like, but if you want to
retain the 'All' option, it must not be changed
. function display_items_per_page()
{
$items = '';
$ipp_array = array(10,25,50,100,'All');
foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value;return false\">$items</select>\n";
}
The next method, display_jump_menu, is another optional method that displays a drop down
menu that will list all the page numbers available and allow a visitor to
jump directly to any page. Using our previous example, if we had a total of
79 pages to display, this drop down menu would list them all so that when
someone selects a page, it automatically will take them to it.
function display_jump_menu()
{
for($i=1;$i<=$this->num_pages;$i++)
{
$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
}
return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page';return false\">$option</select>\n";
}

The last method, display_pages, may be the shortest method, but it's also one
of the most important. This method displays the page numbers on your page.
Without calling it, all the calculations would be done, but nothing would be
shown to your visitor. You need to
call this method at least once in order to display your pagination, but you can also
use it more than once if you like. For example, you could display the page
numbers above AND below your results for convenience. And convenience is
what its all about, no?
So How Do I Use This Thing?
There are three things you need to do in your index.php file before being
able to use your new paginator class.
- First, include the paginator class in the page where you want to use it.
I like to use require_once because it ensures that the class will only be
included once and if it can’t be found, will cause a fatal error. - Next, make your database connections.
- Finally, query your database to get the total number of records that
you'll be displaying.
Step three is necessary so that the paginator can figure out how many records
it has to deal with. Typically the query can be as simple as SELECT COUNT(*)
FROM table WHERE blah blah blah.
You're almost there. Now it's time to create a new paginator object, call a
few of its methods, and set some options. Once you have your total record count
from step three above you can add the following code to index.php:
$pages = new Paginator; $pages->items_total = $num_rows[0]; $pages->mid_range = 9; $pages->paginate(); echo $pages->display_pages();
Let's break it down…
- The first line gives us a shiny new paginator object to play with and
initializes the default values behind the scenes. - The second line uses the query we did to get the total number of records and
assigns it to our paginator's items_total property. $num_rows is an array
containing the result of our count query (you could also use PHP's
mysql_num_rows function to retrieve a similar count if you like). - The third line tells the paginator the number of page links to display. This
number should be odd and greater than three so that the display is symmetrical.
For example if the mid range is set to seven, then when browsing page 50 of 100,
the mid range will generate links to pages 47, 48, 49, 50, 51, 52, and 53. The
mid range moves in relation to the selected page. If the user is at either the
low or high end of the list of pages, it will slide the range toward the other
side to accommodate the position. For example, if the user visits page 99 of
100, the mid range will generate links for pages 94, 95, 96, 97, 98, 99, and
100. - The fourth line tell the paginator to get to work and paginate and finally the
fifth line displays our page numbers.
If you decide to give your visitors the option of changing the number of items
per page or jumping to a specific page, you can add this code to index.php:
echo "<span style="\"margin-left:25px\""> ". $pages->display_jump_menu() . $pages->display_items_per_page() . "</span>";
If you stopped here and viewed your page without adding anything else, you'd see
your page numbers but no records. Aha! We haven't yet told PHP to display the
specific subset of records we want. To do that you create a SQL query that
includes a LIMIT statement that the paginator creates for you. For example, your
query could look like:
SELECT title FROM articles WHERE title != '' ORDER BY title ASC $pages->limit
$pages->limit is critical in making everything work and allows our paginator
object to tell the query to fetch only the limited number of records that we
need. For example, if we wanted to see page seven of our data, and we're viewing
25 items per page, then $pages->limit would be the same as LIMIT 150,25 in SQL.
Once you execute your query you can display the records however you like. If you
want to display the page numbers again at the bottom of your page, just use the
display_pages method again:
echo $pages->display_pages();
More Features
As an added bonus, the paginator class adds "Previous", "Next", and "All"
buttons around your page links. It even disables them when you're on the first
and last pages respectively when there are no previous or next pages. If you
like, you can also tell your visitors that they're viewing page x of y by using
the code:
echo "Page $pages->current_page of $pages->num_pages";
Styling
Finally, you're free to customize the look of your pagination buttons as much as
you want. With the exception of the current page button, all other page buttons
have the CSS class "paginate" applied to them while the current page button has,
can you guess, the "current" class applied to it. The "Previous" and "Next"
buttons will also have the class "inactive" applied to them automatically when
they're not needed so you can style them specifically. Using these three classes
along with other CSS gives you tremendous flexibility to come up with a variety
of styling choices.
Styled:
Unstyled:
Wrapping Up
As you've seen with the pagination class and just a few lines of code you can
tame those giant database lists into manageable, easy to navigate, paginated
lists. Not only are they easier on the eyes but they're faster not only to load
but to browse. Feel free to checkout a couple of demos at
example 1 and
example 2.
- Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.







i will read it later
thanks for that
really usefull. currently trying to integrate it into a module I create for a CMS system. But I have a small problem I get the following link:
http://localhost/Nuke-evo/admin.php?page=3&ipp=2&op=Uploadusers
“&op=Uploadusers” should go before “page=3….”
how do I change this?
Hmm.. I’m thinking of replacing my paging on my website
smutty.ej.am
The coding is great!
but i think there is a little problem with it.
The problem being the comments as they are absent. Please comment the code and i think u’ll get the better mark or comment from who ever since your coding is simple and clear
I didn’t understand this article, where is option to download whole code…? A plenty of story and divided in many parts and at the end – zero.
Dude, you need to put here downloadable example if you wish to call yourself guru for PHP.
Nice tut
If we could get a index.php in the source zip it would be great. when i do exactly what you say i do not get the same result. i get an All at the top of every looped item. What am i doing wrong
Is there any way to call just the next or previous page link from the class?
I have the next and previous link issue worked out by using
$nextpage = $pages->current_page+1;
$prevpage = $pages->current_page-1;
It seems to me that the page that you are currently on shouldn’t be linked at all, and maybe bold it or give it a different style.
Excellent article.
Thanks
Thanks for the paging class mate. After a bit of tweaking here and there in my existing web application functions and was able to get it to work nicely. Cheers!
dsfsdfs67877 test test
where can I see a full example because I can’t manage to make it working
Can someone provide index.php to have a complete example?
Thanx!
Has anyone (aside from Jason) been successful in getting this tutorial to work.
It looks to me it is missing some very important parts. In this case, it looks like Jason is missing too.
He explains the usage in the tutorial, why would you need to see how to use it when he shows you?
What is missing? I made my own database, pulled the content, and used the page-> limit method to limit the SQL call and BOOM, pagination.
Nice work, but I need a working example (index.php) to use this class.
Kindly upload this Class with a complete example. Thanks
For people asking for a sample index.php file. Here is one you can use. Let me know if it works for you.
ENJOY!
limit”;
$qry1 = mysql_query($check) or die (“Could not match data because “.mysql_error());
$num_rows = mysql_num_rows($qry1);
$pages = new Paginator;
$pages->items_total = $num_rows[0];
$pages->paginate();
echo $pages->display_pages();
echo ” “. $pages->display_jump_menu() . $pages->display_items_per_page() . “”;
echo “Page $pages->current_page of $pages->num_pages”;
while($row = mysql_fetch_array($qry1)){
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$company = $row['comapny'];
echo “”;
echo ” $firstname”;
echo ” $lastname”;
echo ” $company”;
echo “”;
}
?>
Sorry, here it is again.
limit”;
$qry1 = mysql_query($check) or die (“Could not match data because “.mysql_error());
$num_rows = mysql_num_rows($qry1);
$pages = new Paginator;
$pages->items_total = $num_rows[0];
$pages->paginate();
echo $pages->display_pages();
echo ” “. $pages->display_jump_menu() . $pages->display_items_per_page() . “”;
echo “Page $pages->current_page of $pages->num_pages”;
while($row = mysql_fetch_array($qry1)){
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$company = $row['comapny'];
echo “”;
echo ” $firstname”;
echo ” $lastname”;
echo ” $company”;
echo “”;
}
?>
Amazing class! Love it really… had a problem with the Previous and Next not showing up so I looked through the source and on line 59 the 10 should be replaced by a 1 I think. Worked fine then
Wonder what it would take to get the current page to no longer be a link in the menu.
line59 if($this->num_pages > 1)
This site never disappointed me. Though there are so many php pagination tutorials out there, but I would say this is the best I’ve found so far. I really like this site very much. Maybe I should donate $100 million to this site. Thank you very much……
php(T_T).\m/ -> php rocksssssss
awful tutorial, he doesnt even show us how to use it on an index.php
can someone please show a index.php correctly.
youre an idiot
great tutorial, indeed. but it seems the index.php part is missing and the URLs of examples are broken. here is the part of my index.php that related to pagination. there are two things that need consideration, the first would be the situation when numebr of rows = 0 or $result is false. another one is $string variable, “$pages->limit” should be added at the end of the second $string variable.
0)
{
$pages = new Paginator;
$pages->items_total = $num_rows;
$pages->paginate();
echo $pages->display_pages();
echo $pages->display_items_per_page();
}
else
{
echo “nothing here”;
}
echo “”;
$string = $string.”$pages->limit”;
$query = mysql_query($string) or die (mysql_error());
$result = mysql_fetch_array($query);
if($result==true)
{
do
{
// code for displaying items
}while($result = mysql_fetch_array($query));
}
echo “”;
if($num_rows>0)
{
echo $pages->display_pages().$pages->display_items_per_page();
}
?>
Here is my blog http://blog.growthsys.com/?p=210
The demo of above code http://www.growthsys.com/examples/pagination/pagination.php
here to download code http://www.growthsys.com/examples/pagination/pagination.zip
ENJOY!
Thanks! This has helped me loads getting it to work.
strange, code could not be uploaded completely:
here i am trying again
$string = “select * from brands order by id”;
$query = mysql_query($string) or die (mysql_error());
$num_rows = mysql_num_rows($query);
if($num_rows>0)
{
$pages = new Paginator;
$pages->items_total = $num_rows;
$pages->paginate();
echo $pages->display_pages();
echo $pages->display_items_per_page();
}
else
{
echo “nothing here”;
}
echo “”;
$string = $string.”$pages->limit”;
$query = mysql_query($string) or die (mysql_error());
$result = mysql_fetch_array($query);
if($result==true)
{
do
{
// code for displaying items
}while($result = mysql_fetch_array($query));
}
echo “”;
if($num_rows>0)
{
echo $pages->display_pages().$pages->display_items_per_page();
}
Rather nice tut but I am really missing some solid examples of how to use it. To me it dosent seem that anything is parsed into the pagination class which makes me wonder on how it should work at all?
Regards
check the website that developed it (catchmyfame.com) for examples. they have a few there plus a sample db.
can you give me one example of damath and its solution for my project. pls
Brilliant!!! Thanks so much!
Hi
I’m having trouble getting this to work. I’m sure its obvious but I’ve been staring at this screen too long now….
When I paste the code in and run the page all I get is
All Page: Items per page:
Page 0 of 0
I get this even though my page returns the required results. It’s just not paginating anything!!!
Please help!!!!!!
Dear All :
I notice all comments example use mysql database.
Can I use this class with ODBC ?
and if is possible please see me sample code how I use.
Thanks a lot.
At first I thought this sucked because I had idea how to implement it. So I then navigated to catchmyfame.com and was able to download a zip containing examples. Now I couldn’t be happier!
– Weird doesn’t that sound like an infomercial pitch?
can someone help me on how to use this code.. plzzz..
yes i can show on my blog
sujatalikhar/wordpress.com
I have an error
“Notice: Undefined index: ipp in paginator.class.php on line 26″
“Notice: Undefined index: page in paginator.class.php on line 36″
means variable “ipp” and “page” is not finding…on line # 24 and 34 respectively..
please help
go to line number 26 and check for
$ipp = isset($_GET['ipp'])?$_GET['ipp']:’0′;
and use this $ipp in subsequent code.
similarly for variable $_GET['page'] .
Here is a simple PJP Pagination tutorial I made in my blog:
http://www.webmastervideoschool.com/blog_item.php?id=15
thanks a lot ……..
I was searching for such code it is really very useful.
thanks once again
Can i have index.php example of this tutorials so that i can figure out how i will use this pagination code with index.php
If you look through the paginate class you’ll realize that a number of his logical operators are formed incorrectly. He writes ‘And’ and ‘Or’ to represent ‘&&’ and ‘||’ which need to be changed in order to parse correctly even though they will not throw errors.
I personally disabled the ‘All’ scripts just because I do not have any use for displaying all of the results, but other than that, this is an excellent code.
Hi! thanks for the script but i am trying to display data and i only see the numbers, i can’t realize from your tut how to display my results. My code is the following:
limit”;
$resSql = mysql_query($queSql, $conexion) or die(mysql_error());
$totSQL = mysql_num_rows($resSql);
if ($totSQL> 0) {
while ($rowSql = mysql_fetch_assoc($resSql)) {
echo ““.$rowSql['nombre'].”“;
echo “Direccion: “.$rowSql['direccion'].”";
echo “Telefono: “.$rowSql['telefono'].”";
}
} else {
echo”No values”;
}
$pages = new Paginator;
$pages->items_total = $totEmp;
$pages->mid_range = 5;
$pages->paginate();
echo $pages->display_pages();
?>
Is this correct?
Thanks in advance
any body knows about Pagination code when you parse data from a XML feed?
any body knows about Pagination code (PHP) when you parse data from a XML feed?
after you change ‘10′ to ‘1′ on line 59, and optionally replace some links for the current page and ‘All’ with spans where appropriate, this paginator class works great. cheers my friend, it’s what I went looking for. ignore any bad feedback – let em reinvent the wheel ..
Great tutorial. See it working on my site at http://www.dvdreward.co.uk/test
Css Code was missing but managed to find it from the example:
.paginate {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
}
a.paginate {
border: 1px solid #000080;
padding: 2px 6px 2px 6px;
text-decoration: none;
color: #000080;
}
a.paginate:hover {
background-color: #000080;
color: #FFF;
text-decoration: underline;
}
a.current {
border: 1px solid #000080;
font: bold .7em Arial,Helvetica,sans-serif;
padding: 2px 6px 2px 6px;
cursor: default;
background:#000080;
color: #FFF;
text-decoration: none;
}
span.inactive {
border: 1px solid #999;
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
padding: 2px 6px 2px 6px;
color: #999;
cursor: default;
}