my $sth = $dbh->prepare("SELECT id, filename, title FROM pictures"); $sth->execute(); print ""; for my $row (1..$nrows) { print ""; for my $col (1..$ncols) { print ""; } print "\n"; } print "
"; my $pic = $sth->fetchrow_hash; if ($pic) { # emit html for the image # data for the picture is in hashref $pic, i.e.: # $pic->{id}, $pic->{filename} and $pic->{title} } else { # emit html for an empty cell } print "
\n";