DBI::ResultPager - creates an HTML-based pager for DBI result sets.
# Create a pageable result set use DBI::ResultPager; my $rp = DBI::ResultPager->new; $rp->dbh($dbh); $rp->query('select books.title, authors.name from books inner join (books.author_id = authors.id)'); $rp->display(); # The same result set, but sorted with nicer column headings my $rp = DBI::ResultPager->new; $rp->dbh($dbh); $rp->query('select books.title as "Title", authors.name as "Author" from books inner join (books.author_id = authors.id)'); $rp->defaultOrder('Title'); $rp->display(); # Adding a custom formatter to build links my $rp = DBI::ResultPager->new; $rp->dbh($dbh); $rp->query('select books.title as "Title", books.isbn as "ISBN", authors.name as "Author" from books inner join (books.author_id = authors.id)'); $rp->addColumnFormatter('ISBN', \&linkISBN); $rp->display(); sub linkISBN { my($isbn) = shift; return '<a href="http://isbndb.com/search-all.html?kw=' . $isbn . '">ISBNdb</a>'; } # Adding a custom column and hiding an identity column my $rp = DBI::ResultPager->new; $rp->dbh($dbh); $rp->query('select books.id, books.title as "Title", from books'); $rp->hideColumn('books.id'); $rp->addCustomColumn('Functions', \&bookFunctions); $rp->display(); sub bookFunctions { my (@row) = (@_); return '<a href="delete.cgi?id=' . $row[0] . '">delete</a>'; } # Set the number of results per page: $rp->perPage(20);
This class is a quick and easy method of paging result sets returned from the DBI database interface. It takes a standard SQL query along with a database handle and performs the query, inserting the resultant rows into a pageable HTML table. Various options such as sort order can be adjusted, and columns can have formatters attached. Columns can also be hidden, and custom columns can be added to the output.
The source for this project should always be available from CPAN. Other than that it may be found at http://www.neuro-tech.net/.
Original code: Luke Reeves <luke@neuro-tech.net> http://www.neuro-tech.net/
Copyright (c) 2005 Luke Reeves <luke@neuro-tech.net>
DBI::ResultPager is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
Luke Reeves <luke@neuro-tech.net>
perl(1), DBI(3).
To install DBI::ResultPager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBI::ResultPager
CPAN shell
perl -MCPAN -e shell install DBI::ResultPager
For more information on module installation, please visit the detailed CPAN module installation guide.