in reply to Not sure how to query my database in this code

my @rows; my @this_row; my $num_per_row = 5; my $in_this_row = 0; while ( my $item = $sth->fetchrow_hashref ) { push @this_row, $item; if ( @this_row >= $num_per_row ) { push @rows, [ @this_row ]; @this_row = (); } }
At this point, you have an AoAoH (array of arrays of hashes). You could now pass this to a Template Toolkit snippet that looks something like:
[% FOR row IN table %] <tr> [% FOR item IN row %] <td>item.id item.filename item.title</td> [% END %] </tr> [% END %]
And you'd end up with something very close to what you have, output-wise. I've left limiting the number of rows to 5 and linking the two snippets as exercises for the reader.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?