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
, 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 |
---|