| | |
Dynamic Next/Prev Buttons in PHP/MySQL
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2005
Posts: 14
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2005
Posts: 14
Reputation:
Solved Threads: 0
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:
And, inversely, for the next row
It's so logical it's embarassing I didn't think of it myself.
--
Aiden

For the previous row:
MySQL Syntax (Toggle Plain Text)
SELECT max(id) FROM `gallery` WHERE id < $currentrecord
And, inversely, for the next row
MySQL Syntax (Toggle Plain Text)
SELECT min(id) FROM `gallery` WHERE id > $currentrecord
It's so logical it's embarassing I didn't think of it myself.

--
Aiden
![]() |
Similar Threads
- PHP and MySQL Web Development (PHP)
- Apache (Linux Servers and Apache)
- Prev/Next Buttons Query (MySQL)
- PHP and MySQL (PHP)
- php, mysql connection (PHP)
- Freelance Web Developer on PHP MySQL for hire (Post your Resume)
- PHP and MySQL newbie introducing self (PHP)
Other Threads in the MySQL Forum
- Previous Thread: Question about select statement
- Next Thread: Search facility for a drop down box
| Thread Tools | Search this Thread |
agplv3 alfresco api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization






