User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 401,735 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,230 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 4766 | Replies: 2 | Solved
Reply
Join Date: Jun 2005
Posts: 14
Reputation: aiden is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
aiden aiden is offline Offline
Newbie Poster

Dynamic Next/Prev Buttons in PHP/MySQL

  #1  
Apr 10th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Posts: 14
Reputation: aiden is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
aiden aiden is offline Offline
Newbie Poster

Re: Dynamic Next/Prev Buttons in PHP/MySQL

  #2  
Apr 10th, 2006
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:

 SELECT max(id) FROM `gallery` WHERE id < $currentrecord 

And, inversely, for the next row

 SELECT min(id) FROM `gallery` WHERE id > $currentrecord 

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

--
Aiden
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,888
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 110
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: Dynamic Next/Prev Buttons in PHP/MySQL

  #3  
Apr 12th, 2006
Hehe. Glad you got it working! Sorry we couldn't have been of more assistance. Thank you for posting your solution.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 9:29 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC