##
SELECT * FROM table
ORDER BY id DESC
LIMIT $lastId, $ammountOfDataToDisplay
####
if ($lastId > 0) {
my $newId = $lastId - $ammountOfDataToDisplay;
print qq~Last~;
}
if ($outputCount == $ammountOfDataToDisplay) {
my $newId = $lastId + $ammountOfDataToDisplay;
print qq~Next~;
}