Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How do you calculate previous/next images from the database (assuming you can't just go ++ or -- as the admin can delete images and thus you could have image16.jpg and the next image in the database be image32.jpg).
My idea was to query the db first and store ALL the picture id's in that category into an array. That way I know what's available. Then query for the picture, then somehow see if there is a previous/next image.. and if so, what it is.
Can someone point me in the right direction?
# prequery to see if there IS a previous/next id my $data = qq(SELECT id, title FROM pictures WHERE category = $categ +ory ORDER BY id ASC); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; my @pictures_in_category; my ($picid, $pictitle); $sth->bind_columns(\$id, \$title); while($sth->fetch) { push(@pictures_in_category, $id); } # real query for the one image you're viewing my $data2 = qq(SELECT id, filename, title, category, description, da +te, views, sensorisospeed, exposuretime, isospeedrating, lensaperture, flash, focallength, cameramodel, shutter +speed FROM pictures WHERE id=?); my $sth2 = $dbh->prepare($data); $sth2->execute($picture) or die $dbh->errstr; ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calculating previous/next from database
by dragonchild (Archbishop) on May 31, 2008 at 03:47 UTC | |
by ikegami (Patriarch) on May 31, 2008 at 04:05 UTC | |
by Anonymous Monk on May 31, 2008 at 05:21 UTC | |
by dragonchild (Archbishop) on May 31, 2008 at 17:09 UTC | |
by parv (Parson) on May 31, 2008 at 08:06 UTC | |
by psini (Deacon) on May 31, 2008 at 12:10 UTC | |
|
Re: Calculating previous/next from database
by igelkott (Priest) on May 31, 2008 at 09:51 UTC | |
|
Re: Calculating previous/next from database
by ides (Deacon) on May 31, 2008 at 15:05 UTC |