/    Sign up×
Community /Pin to ProfileBookmark

Adding Pagination to Gallery Script

Hi,

I have a php gallery that automatically creates thumbnails via GD. [B]I have attached the php file within a zip file. [/B]

What I would like to have help with is I’m not sure how to add pagination to it. I’d like only 6 thumbnails to show up per page and have a type of navigation to go through the pages for a particular album.

Any help would be greatly appreciated! Thanks =]

[upl-file uuid=b3ddc64c-8efb-43db-91a8-e27c7cc095f5 size=5kB]gallery.php.zip[/upl-file]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@valenokOct 03.2007 — you have to select the appropriate images from db of elsewhere

for db you use - LIMIT from,to (WHERE 1 LIMIT 150,156)

will show you 6 images on page 26 (156/6)

for while use for()
Copy linkTweet thisAlerts:
@glitchgirlauthorOct 03.2007 — The thing is -- this script doesn't use a database -- I know how to do it if there was, but I'm building a website for a friend and their host allows php code but no database..
Copy linkTweet thisAlerts:
@MrCoderOct 03.2007 — Get the total amount of images divided by amount per page, in your case 6 this gives us the total number of "pages". (Use ceil())

Use a $_GET variable to store the current page number, we will call this $_GET["page"], default is 0.

Then simple build a sorted array of all the images in a folder and array_shift() 6 * $_GET["page"] images before displaying the final 6 images you want to display.
Copy linkTweet thisAlerts:
@valenokOct 03.2007 — I bet if she knows how to use limit she would deal with GET parameters.

Where do you store your images ?

In a folder getting them into array by readdir ?

You should sort you array by file's creation time back to front to ensure you have the latest newest images on the first page. use [I]multisort[/I] and [I]filectime[/I]

Then you just output them even not in cycle

< img src='createthubnail.php?img=".( intval($_GET['s']) + 1) ."'>

..

< img src='createthubnail.php?img=".( intval($_
GET['s']) + 6) ."'>

echo "<a href='?".($s+7)."'>nextpage";
Copy linkTweet thisAlerts:
@knightmanOct 11.2008 — any link(s) to see a working sample?
Copy linkTweet thisAlerts:
@sushiOct 13.2008 — Hey I have an idea for you.. you could encapsulate each set of images in divs with a class. And control them with javascript:

[CODE]link 1: onclick hide all except firstSet
link 2: onclick hide all except secSet
etc..


<div class="firstSet">lalalal 5 thumbs here alal</div>
<div class="secSet">lalalal alal</div>
<div class=thirdSet">lalalal alal</div>[/CODE]
×

Success!

Help @glitchgirl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...