Forum Moderators: coopster

Message Too Old, No Replies

Scrolling through pictures

Sounds easy. Will it be?

         

danmccarthy

6:58 am on Feb 13, 2005 (gmt 0)

10+ Year Member



I've got 100 photos going up on my new site. Each one is on it's own php page. The caption, copyright info, and filename for the image itself are going to be pulled from a MySQL database. That part I can do easily. I say "easily" now when this is just theory, i'll be crawling back to you later when I get my 50th parse error.

What I'm asking for help with is linking these 100 image pages to one another (and the first and last ones to the main page) with next and previous buttons. Ideally what I'd like after this is all done is to be able to upload some new pics each week, add the php pages for them, add their records to the database, and have the next/previous links automatically just "work" integrating the new images with all the old images.

This would be easy if the photo id field (which is also the primary key for the table) held all consecutive numbers (say 1-100), as I could just add or subtract 1 from the ID of the current photo, and I'd be set. The problem is, any time a photo is deleted from the database, a gap is created in the autonumbered photo_ID field, and the +1 or -1 thing just won't work, I don't think. I know what I'm trying to do should be easy -- I'm new to PHP, but I'm still pretty sure this is something I know HOW to do, I just can't think of the way to do it.

Any ideas? Does this make any sense?

Thanks for any help...

Dan

grandpa

8:01 am on Feb 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is more than one way to skin this cat. You are correct in that the auto-increment field could contain gaps. So, you could load the image names into an array first, then you have an array with keys that do not contain gaps.

hakre

9:08 pm on Feb 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



let me try to skin the cat in another way:

query the table for the id bigger then the current one, but return only the smalest.

SELECT id FROM photos WHERE id > $currid ORDER BY id ASC LIMIT 1

that way you have to have 2 queries then, but not so much data as reading everything into an array first.

danmccarthy

4:07 am on Feb 14, 2005 (gmt 0)

10+ Year Member



I will try one or both of these methods this week. Thank you both for skinning the cat. It always helps to give it a couple shots, because those damn things just don't skin easy. Eight times i've tried. Maybe one more try will do it.

(No animals were harmed in the making of this script)

carguy84

4:12 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got 100 photos going up on my new site. Each one is on it's own php page.

If the information is stored in the database, then you're talking about one dynamic PHP page, right? And not 100 pages with the same code on it?

danmccarthy

4:59 am on Feb 14, 2005 (gmt 0)

10+ Year Member



I am planning to create 100 php pages that all consist of one common include and one hard-coded variable that indicates which record (photo, caption, etc) to pull from the database. So blue-widget.php would look something like this:

<?
$photo-id=1;
include("shared-photo-code.php");
?>

I know I could have just one file and do something like photos.php&id=1, photos.php&id=2, etc, but I am trying to avoid urls with dynamic query strings attached. I also want to use filenames that are descriptive of the content on the page.

This also seems (to me) a lot easier than using mod_rewrite.

Am I totally off my rocker?

grandpa

6:14 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Am I totally off my rocker?

You're more likely just in the right place...

I did something like this way back in my early html days, but without php or a database. Each document was hand coded for the next, or the previous. What a pain, but somehow fulfilling too.

Today I might do it differently. The Next/Prev links would be forms with hidden values; values retrieved from the database. Then I could write a single document, and on form submission the document would be refreshed with the correct pic, as well as any unique page titles, descriptions, etc., all stored in a table.

So, while it might be redundant to create a lot of very similar pages, it's doable and no indication of the position on your rocker. Do what you can today - in a few weeks/month/years you'll know enough to do it all over again - some other way.