How do you deal with first and last image then?
I insist on my belief that a primary key should be doing
only one task, i.e. identifying the record uniquely. If you
need a display id, you have two choices:
- Adding a field to your table for display purposes,
but then you would have two further problems.
- filling the gaps when you delete a record.
- Always displaying the records in the same order.
No chance of diplaying with different criteria.
- Creating a display number when you select the records.
And you can do it either in (at least) two ways:
- with a MySQL variable.
SELECT @count := @count+1 as sequence, id, name, filename from mytable
- In your Perl script.
my $query = "SELECT id, name, filename from mytable";
my $sth=$dbh->prepare($query);
$sth->execute();
my @results;
my $count =0;
while (my $row = $sth->fetchrow_arrayref) {
push @results, [ $count++ , @$row ]
}
Now your @results have a counter that you can use for displaying purposes.
Modifying your query with a different WHERE or ORDER BY will change the display order.