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 @saved_results; print qq(); my $data = qq(SELECT id, filename, title FROM pictures ORDER BY ID DESC); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; my ($id, $filename, $title); $sth->bind_columns(\$id, \$filename, \$title); while ($sth->fetch) { push(@saved_results, $id); } print @saved_results; 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; } #Retrieve your image from server here and #put the corresponding tags print qq(\n); # query the database via id here $count++; last if $count == $total_images; } print "\n"; last if $stop; } print qq(
. $saved_results[$count++]
); }