/    Sign up×
Community /Pin to ProfileBookmark

Picture gallery thing….

Hi,

I would like to be able to set up a page that has a picture and two buttons, previous and next. Of course if you are on the first image then the previous button would not show. The last image would not have a next button either.

What I was wondering, is this possible to do without creating a seperate page for each image and how do I do this. Is this something I would have to use querying strings for? I am somewhat new to php so be easy on me. ?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@fozeratorMay 31.2005 — Yes. It is possible, and relatively easy... Do something like this:

[code=php]
$image_array = array('img url', 'img url 2'); /*You can dynamically create this based on the contents of a folder*/

/*Call this page something like gallery.php
You will have to pass an argument to it, let's say it's something like gallery.php?picture=x
where x is the index of the picture that you want (as it is in the array) */

if(empty($_GET['picture'])){
$picture = 0; //Start with the first picture if there is no picture defined....
}else{
$picture = $_GET['picture'];
}

$picture_url = $image_array[$picture]; //This returns the url of the specified image...

if($picture <> 0){
$previous_link = '<a href="gallery.php?picture='.($picture - 1).'">Previous</a>';
}else{
$previous_link = '<i>Previous</i>';
}

if($picture < count($image_array)){
$next_link = '<a href="gallery.php?picture='.($picture + 1).'">Next</a>';
}else{
$next_link = '<i>Next</i>';
}
echo ' <html>
<head>
<title>Picture Number: '.$picture.'</title>
</head>
<body>
<p align="center"><img src="'.$picture_url.'"></p>';
<p align="center>'.$previous_link.' | '.$next_link.'</p>
</body>
</html>';
[/code]


Now I just wrote that here in the wd editor, so I'm not too sure if there are any parser errors, etc...

Good luck, hope that helps,

James.
Copy linkTweet thisAlerts:
@towerboyauthorJun 01.2005 — Thanks for something to work with. I tried the script but it has a parse error on line 33. That is were it would write the "previous | next" links to the page. The only thing I could see was that the word "center", did not have closing quotes. I fixed that but still had the parse error on 33. Any Ideas?
Copy linkTweet thisAlerts:
@SpectreReturnsJun 01.2005 — On this line

<p align="center"><img src="'.$picture_url.'"></p>';

remove the last two characters ('?
Copy linkTweet thisAlerts:
@towerboyauthorJun 01.2005 — Hey, it works! ...almost all the way. It seems to think there is one more image than I have set. I set three images and on the third image, it still has a link for a forth image, but since there is nothing there, it shows nothing. On the "forth image", the "next" link is italicized.

I tried changing the equation stuff on:

if($picture < count($image_array)){

but it didn't seem to help. Most of this makes sence to me but I can't figure this out.
Copy linkTweet thisAlerts:
@fozeratorJun 01.2005 — sorry about the errors... Anyway, change this line:

if($picture < count($image_array)){

to

if($picture < count($image_array) - 1)){

Since we start at 0 for the first picture, suppose a total of X pictures... The last picture will be index X-1,

which means the count should be reduced 1 (or the picture index + 1) to determine if the last picture is the one shown...

-James
Copy linkTweet thisAlerts:
@towerboyauthorJun 01.2005 — Alright, it works great now. There was on error however. You added an extra closing paranthesis that should not be there. It should look like this:

if($picture < count($image_array) - 1){

you had:

if($picture < count($image_array) - 1)){

No big deal, it got sorted out. Thanks a lot everyone!
Copy linkTweet thisAlerts:
@fozeratorJun 01.2005 — ? I rely too much on Eclipse highlighting closed parentheses and brackets.
×

Success!

Help @towerboy 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.28,
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,
)...