944,171 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 10991
  • MySQL RSS
Apr 10th, 2006
0

Dynamic Next/Prev Buttons in PHP/MySQL

Expand Post »
I've constructed a photo gallery with a dynamic CMS backend that allows the content providers to upload, delete, etc images. All images are stored as reformated jpeg files (processed by the GDLib on upload) and the relevant metadata is stored in a table called `gallery`.

References are made by an integer auto_incremement pkey called, as usual, `id`.

So, if someone clicks a gallery thumbnail, a popup window to display the image opens with a URL referenced var of $id passed to the display.php file which creates the popup content dynamically. For instance:

[HTML]<a href="display.php?id=1023">[/HTML]
Note: it actually uses a javascript window.open abstraction, but for the sake of simplicity, imagine it's a symantic anchor

Here's the question: Naturally, with auto_increment, if a file is deleted there is a gap created in the $id sequence. Therefore, the next and previous buttons can't simply search a validity check for $id++ or $id-- : I actually have to determine what row the previous result was on, and then query the `id` field values for the previous and next rows.

I'm assuming this will involve some limits and an array, but nothing I've tried is working properly. Any suggestions? Has anyone done this same thing with a similar reference mechanism?

Thanks.
--
Aiden
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aiden is offline Offline
14 posts
since Jun 2005
Apr 10th, 2006
0

Re: Dynamic Next/Prev Buttons in PHP/MySQL

Thanks to a reply on another forum, I have found a solution. I'm posting it here for the integrity of the forum archives and future searchers such as myself

For the previous row:

MySQL Syntax (Toggle Plain Text)
  1. SELECT max(id) FROM `gallery` WHERE id < $currentrecord

And, inversely, for the next row

MySQL Syntax (Toggle Plain Text)
  1. SELECT min(id) FROM `gallery` WHERE id > $currentrecord

It's so logical it's embarassing I didn't think of it myself.

--
Aiden
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aiden is offline Offline
14 posts
since Jun 2005
Apr 12th, 2006
0

Re: Dynamic Next/Prev Buttons in PHP/MySQL

Hehe. Glad you got it working! Sorry we couldn't have been of more assistance. Thank you for posting your solution.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Question about select statement
Next Thread in MySQL Forum Timeline: Search facility for a drop down box





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC