James Kelty <[EMAIL PROTECTED]> said something to this effect on 07/03/2001:
> I have connected to a MySQL database, and I am creating a table
> based on the row fetched which is not a problem. But! How can I
> write a table when multiple rows are fetched without writing a
> new table for each row?
end_table has a corresponding start_table; print this outside the
for loop.
print $cgi->start_table({-border => 1});
while(@row = $query->fetchrow_array()) {
print $cgi->Tr({-align=>LEFT, -valign=>MIDDLE},
[ $cgi->td({-bgcolor=>'green',-width=>'150'},[ @row [0..3] ]) ],
);
}
print $cgi->end_table;
Another option is DBI's fetchall_arrayref method. I usually
prefer to fetch all the data at once and iterate over it using
map, or a for loop.
my $all_rows = $query->fetchall_arrayref();
# Done with $query here; $all_rows has all the data
print $cgi->start_table({-border => 1});
for my $row ( @{ $all_rows } ) {
print $cgi->Tr({-align=>LEFT, -valign=>MIDDLE},
[ $cgi->td({-bgcolor=>'green',-width=>'150'},[ @{$row}[1..3]] ]
}
print $cgi->end_table;
(darren)
--
One man's "magic" is another man's engineering. "Supernatural" is a
null word.
-- Robert Heinlein