Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
After playing around for most of the day today I got one that works great in the command line. I can't figure out from the code below how I'd fetch my database results. It may be due to work overload right now but I can't seem to grasp it. Can someone shine some light on this task for me?
Please forgive the not-so-perfect alignment, haven't gotten around to cleaning it up yet.
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(<table>); 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 "<tr>"; 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(<td> . </td> ); } $stop = 1; last if $stop; } print qq(<td> $id $filename $title </td>\n); $count++; last if $count = $total_images; } print "</tr>\n"; last if $stop; } } print qq(</table>); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Not sure how to query my database in this code
by sulfericacid (Deacon) on May 11, 2008 at 02:34 UTC | |
|
Re: Not sure how to query my database in this code
by pc88mxer (Vicar) on May 11, 2008 at 05:23 UTC | |
|
Re: Not sure how to query my database in this code
by planetscape (Chancellor) on May 11, 2008 at 07:58 UTC | |
|
Re: Not sure how to query my database in this code
by dragonchild (Archbishop) on May 11, 2008 at 18:31 UTC |