JimJx has asked for the wisdom of the Perl Monks concerning the following question:
Anyway, I am trying to use HTML::Pager after a search in MySQL. So, my question is how do I get the search results into Pager?
Thanks for reading!
Jim
#!/usr/bin/perl -w use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; $|++; use strict; use warnings; use diagnostics; use DBI; use CGI; use HTML::Pager; my $row; # get CGI query object my $query = CGI->new(); my $dbname = "DBI:mysql:farthing_valleyweb"; my $dbusername = "farthing_farthin"; my $dbpassword = "ginajim"; my $dbh = DBI->connect($dbname, $dbusername, $dbpassword, { RaiseError => 1, PrintError => 0 }); # The sql for selecting out of the DB my $sql = 'select * from valley where category like "Real Estate"'; # Prepare the SQL and then execute it my $db_query = $dbh->prepare($sql); $db_query->execute(); # store each record into @results while (my @results = $db_query->fetchrow_array()) { push(@results, $row); } # create a callback subroutine to generate the data to be paged my $get_data_sub = sub { my ($offset, $rows) = @_; my @return_array; for (my $x = 0; $x < $rows; $x++) { push(@return_array, [ $row ]); } return \@return_array; } ; my $pager = HTML::Pager->new( query => $query, get_data_callback => $get_data_sub, rows => 100, page_size => 3, ); # make it go - send the results to the browser. print $pager->output;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML Pager
by moritz (Cardinal) on Aug 22, 2007 at 11:43 UTC | |
by JimJx (Beadle) on Aug 22, 2007 at 12:36 UTC | |
by moritz (Cardinal) on Aug 23, 2007 at 08:07 UTC | |
by Anonymous Monk on Aug 23, 2007 at 08:01 UTC |