![]() |
Pagination
Since i seen someone request one. I thought i would write a quick one :-)
You can view demo HERE Firstly connect to your database using the following PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
PHP Code:
Ok now we have the total number of values we now need to work out just how many pages thats going to use. PHP Code:
PHP Code:
PHP Code:
Full Code: PHP Code:
PHP Code:
|
Nice article.
But why is there an ' at the end of each page number? |
Damnit, you beat me to it! ;)
I was going to write an article about pagination aswell after I read some post in the "Top 10 scripts a programmer should code" or whatever that topic was called ;) Nice article :) |
Quote:
Sorry Tanax haha :-) couldn't help myself :-) |
Quote:
|
Well, this pagination will just keeping going, why not make it so that theres like
1,2 .. 8, 9 a bit like what Google does? |
Nice article, thanks for sharing. My only gripe would be that the code is not very flexible. You should wrap it in a class which can then be used in your projects.
|
Well as i did say it was a quick one, but ill happily improve on it and add to it make it a bit more friendly. :-)
|
It'd be really awesome if you could do the 1,2 .. 8, 9 thing
|
Quote:
I have updated the code above well added an extra bit just replace the link code. Its not exactly like the google one, but it doest clog the page with lots of links. |
It is what it is: a nice and simple pagination class. If you were to get all complex about it then I'd be inclined to take the approach of passing in the format you wish the pagination to be returned as. Such as:
php Code:
It would also be more programmer-friendly if you could pass in the total amount of records into the class, and how many you would like per page - and if you wanted to take that further then which column you want the items to be ordered by. In fact, thinking about it, instead of passing in the SQL result yourself, you would specify just the SQL clause and the class would do the rest for you. For example: php Code:
Unless anybody has a better solution then that's how I would currently do it if I were to write a pagination class, in conjunction with the passing in the pagination type to the class construct. |
Quote:
But if I would, I would probs want to do pagination by class. And I have no idea how to do that :| :P |
I shall get on writing a class for it and will either post it up if no one has done so :-)
|
| All times are GMT. The time now is 06:43 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0