DBI::ResultPager - creates an HTML-based pager for DBI result sets.


DBI-ResultPager documentation  | view source Contained in the DBI-ResultPager distribution.

Index


NAME

Top

DBI::ResultPager - creates an HTML-based pager for DBI result sets.

SYNOPSIS

Top

 # 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);

 # Vertically align the outputted columns:
 $rp->alignRows('top');

 # Get the outputted table as a scalar
 my $output = $rp->getOutput();

DESCRIPTION

Top

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.

METHODS

Top

dbh

This sets the DBI database handle for query execution.

addColumnFormatter (name, formatter)

Adds a custom formatting routine to a column. When a row of that column is rendered, the customer format routine is called with two parameters - the value of the data in that cell, and a list reference containing the current row of the resultset. The list reference is useful for referring to other elements in the current row.

SOURCE AVAILABILITY

Top

The source for this project should always be available from CPAN. Other than that it may be found at https://neuro-tech.net/.

AUTHOR

Top

	Original code:		Luke Reeves <luke@neuro-tech.net>
				https://neuro-tech.net/

COPYRIGHT

Top

CREDITS

Top

 Luke Reeves <luke@neuro-tech.net>

SEE ALSO

Top

perl(1), DBI(3).


DBI-ResultPager documentation  | view source Contained in the DBI-ResultPager distribution.