HTML::DataTable::DBI - Print HTML tables from SQL queries
Version 0.54
use HTML::DataTable::DBI; my $list = HTML::DataTable::DBI->new( data => $cgi_data, columns => [ # hashrefs describing column formats ], sql => 'SELECT * FROM table_name WHERE foreign_key = ?', sql_params => [ $some_value ], delete => { } # Delete spec as shown below ); print $list;
Look in HTML::DataTable for column-definition and table formatting attributes
A list containing a DBI connect string, username, and password.
You can supply a live DBI database handle instead of a DSN.
A SQL query with optional "?" placeholders, which will be run and its results formatted and shown in the table.
An optional arrayref containing the actual parameters for the SQL query.
An optional hashref telling the list what record to delete. If this is included, a column will be added to the table to show trash icons. The hashref can take either of two forms. If the SQL query for this table is not parameterized - that is, the record's ID is all we need to know which record to delete - then the hashref can simply map the column index of the record ID to the CGI argument that supplies the one to delete:
delete => { sql => 'DELETE FROM table WHERE record_id = ?', id => [ 0 => $args{delete} ], }
whereas if the query had a parameter the delete hashref has to give both the local and foreign keys:
delete => { sql => 'DELETE FROM table WHERE record_id = ? AND foreign_id = ?', local => [ record_id => $args{speaker_id} ], foreign => [ 0 => $args{delete} ], }
An optional "noun" attribute in that hashref can supply a word to replace "record" in the delete confirmation alert.
The URL of a trash can icon for use in the "Delete" column - defaults to /art/trash.gif.
A paramterized SQL query that will be run to get results for this column.
The index of the column in the results from the main table's SQL query that will be used in the column's query's parameter. Defaults to 0.
A character string that will be used to concatenate the results of the columns's query. Defaults to ", ".
HTML::DataTable
Nic Wolff <nic@angel.net> Jason Barden <jason@angel.net>
To install HTML::DataTable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::DataTable
CPAN shell
perl -MCPAN -e shell install HTML::DataTable
For more information on module installation, please visit the detailed CPAN module installation guide.