|go ahead... be a heretic|
Building an index for next/last in a photo album.by Seumas (Curate)
|on Jul 26, 2004 at 20:05 UTC||Need Help??|
Seumas has asked for the
wisdom of the Perl Monks concerning the following question:
I slept on this problem and woke up without a solution, so I'm finally turning to my fellow monks.
I have a photo album system. When you submit a URL where part of the query contains img_id=# - the img_id is used to do a lookup in the database and pull out the information on that record, including its disk location. Then this image is displayed on a page by itself.
On the page with the photo, I want to display a preview thumbnail of the photo just before this one and after so they can be clicked to progress through the system.
The problem is, I can't figure out how to pull the target record, plus the one before and after it in a single SQL query. I suppose that can't be done. So I decided as a workaround, I would do a selectall_arrayref() against the album_id and build an index out of it. Then I could find what index number the target record is in, in that array. TO get the previous and next images, I could subtract and add one from the index and grab the values out of them.
For example, I want to get img_id #43 from the database, so:
The problem, of course, is that selectall_arrayref is an arrayref and to do this, I'll need just a regular array. So what would be the quickest/shortest way to turn the $album_idx = $dbh->selectall_arrayref() into just an array?
Or... could anyone with more experience offer another solution to my whole confounded "building an index of img_id's from the database" to keep track of the pevious/next images?
Edit: I'm using PostgreSQL.