![]() |
Pagination class
Hello.
I'm releasing my pagination class. I already wrote it in another topic while helping someone, so I thought I'd just make an own topic for it. I've improoved it since I posted it in that other topic, and now I've written descriptions of each function. Also, this *should* work without MySQL, eventhough my example is based on MySQL. php Code:
Example usage: php Code:
I started working on an example to use this with a gallery, where the image files were in a image dir. But I got stuck. More specificly I got stuck when I was trying to get the results within the first result on a page, and the last result on a page, based on the value of the max nr of results per page. Maybe someone else can try to work it out? Anyways, this is my pagination class. Any comments? :-) |
An example which uses a directory of images is given below. The folder structure is such that we have an images folder and within that a thumbs folder. Filenames match between the folders representing a thumbnail and full-sized version of the same image. It's up to you to create the thumbnails however you like.
PHP Code:
|
Thanks guys, very handy :-)
Alan |
Quote:
And thanks for moving it ;-) Well, I'm glad that it seems to work without MySQL aswell, because that was my intention, to not just limit the class to a MySQL based pagintion :-D :-D |
I just see a bad thing in your class. To use it, you have to keep your mysql connexion opened all the time your page is loading. It's not safe or optimized if the display of your current page is heavy/long :)
Whatever, indeed, it's useful :) |
Finally someone that doesn't mix up sql with pagination, good job!
|
nice work ;) learned some new things ;) ty!
|
Quote:
Thank you :-) Quote:
Thanks again Quote:
|
Quote:
That's my job, to learn something new, "almost" everyday, but more importantly absorb and understand. I won't copy your code but I will use it as a reference along with websavvy's method, so don't worry if it's old. I will never learn OO if I just copy someone's code... I gotta grind it out like everyone else here did one time! |
Quote:
Of course, it's good that you don't just copy paste, it's better to read it through and understand what everything does and why it's there. |
Tanax, question about a piece of your code.....
What does it mean when you say "return false", and you also say "return true", but what are you actually returning? Code:
public function checkLink($pagenr) { |
Quote:
PHP Code:
|
Like Kalle said, its' function is to validate if the page in the parameter is a valid page in the array of pages.
So I'm returning true if it exists in the array of pages, and false if it does not. When I then check: PHP Code:
PHP Code:
|
Ahh I see now.
Thanks again Kalle/Tanax... Since the return is "true". Then it just returns the number that you are checking right? so say 5 is a good number, then you get 5 back? Since PHP is loosely typed, do you have to do "return false" if the number doesn't check out? It sounds like good practice to do that anyways, but just wondering. |
You should change getPages so that you can give it a int value OR an array of data. Like so:
PHP Code:
|
Quote:
return range(1, $this->totalPages) in place of that entire chunk? |
Quote:
Also, getCurrentPage() could be reduced to: PHP Code:
|
Quote:
|
Quote:
Quote:
Quote:
|
Quote:
|
| All times are GMT. The time now is 09:19 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0