sub display_pictures { my $rowcnt = 5; my $colcnt = 5; my $total_images = $rowcnt * $colcnt; my $count = 0; my $tags_to_close = 0; # ensure all html tags are good my $stop; my $counted_in_row = 0; my $data = qq(SELECT id, filename, title FROM pictures WHERE 1); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; print qq(); my ($id, $filename, $title); $sth->bind_columns(\$id, \$filename, \$title); while ($sth->fetch) { for( my $i=0;$i<$rowcnt;$i++) # for 1 .. 5 for rows { print ""; for(my $j=0;$j<$colcnt;$j++) # for 1 .. 5 for pictures { $counted_in_row++; if ($count == $total_images) { my $tags_to_close; $tags_to_close = $colcnt - $j; $tags_to_close = 0 if $tags_to_close == $colcnt; for (1 .. $tags_to_close) { print qq( ); } $stop = 1; last if $stop; } print qq(\n); $count++; last if $count = $total_images; } print "\n"; last if $stop; } } print qq(
. $id $filename $title
); }