Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Build Table with 'n' rows and 'm' columns

by Samy_rio (Vicar)
on Nov 02, 2006 at 09:19 UTC ( #581857=note: print w/ replies, xml ) Need Help??


in reply to Build Table with 'n' rows and 'm' columns

Hi, Try like this,

use strict; use warnings; use DBI; use HTML::TableTiler; my @matrix; my $dbh = DBI->connect( "DBI:mysql:project") or die "Can't connect to +Oracle database: $DBI::errstr\n"; my $sth = $dbh->prepare("select * FROM modules"); $sth->execute || $sth->errstr(); while (my @row = $sth->fetchrow_array) { push (@matrix, [@row]); } $dbh->disconnect; my $tt = HTML::TableTiler->new(); print $tt->tile_table(\@matrix);

Thanks ikegami++

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';


Comment on Re: Build Table with 'n' rows and 'm' columns
Select or Download Code
Re^2: Build Table with 'n' rows and 'm' columns
by ikegami (Pope) on Nov 02, 2006 at 09:33 UTC
    There room for a some small improvements.
    • You don't check the result of $dbh->prepare.
    • You don't check the result of $dbh->fetchrow_array.
    • Your loop can be replaced with $sth->fetchall_arrayref.
    • You can also condense the code further using $dbh->selectall_arrayref.
    use strict; use warnings; use DBI (); use HTML::TableTiler (); my $dbh = DBI->connect("DBI:mysql:project") or die "Can't connect to Oracle database: $DBI::errstr\n"; my $matrix = $dbh->selectall_arrayref("SELECT * FROM modules"); die "Unable to fetch query results: $DBI::errstr\n" if $dbh->err; my $tt = HTML::TableTiler->new(); print $tt->tile_table($matrix);

    Update: I was obviously tired! Fixed the problems identified in replies.

      there is still room for some small improvement!
      Global symbol "$sth" requires explicit package name
      ;-)
        And more. Personally, I prefer using SELECT over SELET ;-)
Re^2: Build Table with 'n' rows and 'm' columns
by andyford (Curate) on Nov 02, 2006 at 15:10 UTC
    Ha Ha I like they way you mess with your users: failure to connect to a mysql database sends them looking for a failed Oracle instance.
    Evil genius!
    my $dbh = DBI->connect( "DBI:mysql:project") or die "Can't connect to +Oracle database: $DBI::errstr\n";

    Update: Added code for quick reference.

    andyford
    or non-Perl: Andy Ford

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://581857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (16)
As of 2015-07-02 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (38 votes), past polls