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; ...
In reply to Calculating previous/next from database by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |