in reply to How can I display an entire MySQL table in Perl?

These are all good suggests, but I have yet another way.

I am not sure you said that you wanted to put the db table into an html table. Assuming that you simply wanted to get the data, extract in whole and then put it into an arbitrary html form or any form for that matter, you might try using fetchrow_hashref which I like because it allows you to preserve the column names as keys for easy access.

This means that if the column names are unknown or you change tables you will be able to reuse your script and have access to the column names.

I then use Template Toolkit as a template processor for displaying that data.

(I do like the idea of doing it one fell swoop so I will look into DBIx::XHTML.)

Edited by footpad, ~Wed Jan 2 07:11:39 2002 (GMT)

  • Comment on Re: How can I display an entire MySQL table in Perl?

Replies are listed 'Best First'.
Re: Re: How can I display an entire MySQL table in Perl?
by hakkr (Chaplain) on Jan 02, 2002 at 18:34 UTC

    use hashes and arrays with an array of hash refs

    my @rows= (); # an array reference while (my $row= $sth->fetchrow_hashref) { push (@rows, $row); } #you can then pass the array of hash refs straight to an #HTML template loop construct or iterate over the array as #below foreach my $str (@$rows) { print $str->{'id'}; }