One of the most repetitive work on web applications are the creation of lists of data. Generally all the lists on the application have similar characteristics and same looking. Some time ago i will do all the job by hand on every list, this make me crazy after some dozens of similar lists.

To save some time i create the CGI::List module. This is the result after some years of development and use.

#List
my $list = CGI::List->new(
dbh => $dbh,
sql => {
select => "*",
from => "countries",
limit => "20",
},
);
#Print the list
print $list->print();

Whit this code i have an html list whit auto order and pagination.

Easy i can put a link on each row using the row key as a cgi param.

link => {
key => "id_country",
hidde_key_col => 1,
location => "params.pl",
transit_params => {aditional_param => "param_value"}
},

If you like how sound this, go to: http://www.cgi-list.com to see all the examples.

The CGI::List features are: Columns name autodetection, Auto Order, Auto Pagination, CSS Based, Columns Totals (SUM, COUNT, AVG), Conditional row formats based on a cell value, Conditional cell formats based on a cell value, Http links based on rows key.

Replies are listed 'Best First'.
Re: Easy create HTML lists from a database
by amarquis (Curate) on Feb 12, 2008 at 17:03 UTC

    Looks neat, but it took me a minute to realize that it output an HTML table rather than a literal list (as in, ul and ol elements).

    Is there a method to return the result as a string instead of printing it?

    I do a lot of quick 'n dirty Database query -> HTML sorts of things, and will be grabbing this just to eliminate some steps in that process. Thanks for uploading it!