NAME DBIx::XHTML_Table - Create XHTML tables from SQL queries SYNOPSIS use DBIx::XHTML_Table; my $table = XHTML_Table->new( $datasource, $username, $password ) || die "could not connect to database\n"; $table->exec_query(" SELECT TITLE,ALBUM,YEAR,GENRE FROM MP3.SONGS WHERE YEAR=? AND GENRE=? ORDER BY ARTIST ",[$year,$genre]); # save a raw copy for later my $raw = $table->get_table; # start tweaking the table $table->modify_tag('TABLE',{ border => 1, cellspacing => 0, }); # modify all tags $table->modify_tag('TH',{ bgcolor => 'black', style => 'Color: white;', }, 'header'); # modify only tags for TITLE column $table->modify_tag('TD',{ align => 'right', # although align is deprecated bgcolor => '#ABACAB', },'title'); # modify only tags for ALBUM and YEAR columns # columns - in this case, each column will permuate # the colors and the alignment value $table->modify_tag('TD',{ width => 200, align => [qw(left center right)], bgcolor => [qw(green blue red)], },[qw(album year)]); # impress the boss with rotating row colors # (this would override the above method) $table->set_row_colors( ["#D0D0D0", "#B0B0B0")], [qw(album year)], ); # suppress duplicates on a group $table->set_group('album',1); # since we can, sum up the years column # totals will be wrapped in 's belonging to # optional sprintf mask can be used for formatting $table->calc_totals('year','%.02f'); # and if you have a well behaved group set . . . $table->calc_subtotals('year','%.02f'); # print out the complete table print $table->get_table; # compare it with the raw version print $raw; DESCRIPTION XHTML_Table will execute SQL queries and return the results wrapped in XHTML tags. Methods are provided for determining which tags to use and what their attributes will be. Tags such as , ,
, and will be automatically generated, you just have to specify what attributes they will use. This module was created to fill a need for a quick and easy way to create on the fly XHTML tables from SQL queries, for the purpose of 'quick and dirty' reporting. If you find yourself needing more power over the display of your report, you should look into templating methods such as HTML::Template or Template- Toolkit. Another viable substitution for this module is to use DBIx::XML_RDB and XSL stylesheets, but some browsers are still not XML compliant, and XHTML_Table has the advantage of displaying at least something on browsers that are not XML or XHTML compliant. At the worst, only the XHTML tags will be ignored, and not the content of the report. AUTHOR Jeffrey Hayes Anderson COPYRIGHT Copyright (c) 2001 Jeffrey Hayes Anderson. All rights reserved. DBIx::XHTML_Table is free software; it may be copied, modified, and/or redistributed under the same terms as Perl itself.