in reply to Re: reading all images in a directory
in thread reading all images in a directory
You have a blank trailing row if the number of images is divisible by 5. Fix:
$i = 0; $open = 0; foreach (@images) # or: while ($sth->fetch) # or: while (readdir(IMAGE_DIR)) { (print "<tr>", $open = 1) unless $open; print "<td>"; # print image print "</td>" (print "</tr>", $open = 0) unless ++$i % 5; } print "<tr>" if $open;
As a bonus, I wrote the fix such that you don't have to know how many images there are in advance (just like in the original solution). This is very useful when reading from a database.
|
|---|