HTML::Pager, Navigation not working

Y

yesvee

Hi geeks,

I tried to use HTML::pager to display my database contents. The
contents are displayed but navigation doesnot work. I have given my
code below.

----

#!/usr/bin/perl

#uses
use strict;
use warnings;
use diagnostics;
use DBI;
use CGI;
use HTML::pager;

#Declare Variables
my $query=CGI->new();
my $count=0;

#Fetch DB Connects

my $get_data_sub = sub {
my (@return_array,@data);

#connect db & prepare stmt
my $dbHandle =
DBI->connect("dbi:mysql:tempdb","user","password") or die ("Cannot
Connect to database");
my $stmtHandle = $dbHandle->prepare("select sno,name,age,deptno
from sample1");

#fetch content from Database
$stmtHandle->execute();

while(@data=$stmtHandle->fetchrow_array())
{
push(@return_array, [@data]);
}

#disconnect db
$stmtHandle->finish();
$dbHandle->disconnect();

return \@return_array;
};

#Pager
my $pager = HTML::pager->new(query=>$query,
get_data_callback => $get_data_sub,
rows => 11,
page_size =>5,
cell_space_color => '#000000',
cell_background_color => '#ffffff',
debug => 1
);

print "Content-Type: text/html\n\n";
print $pager->output;
 
P

Paul Lalli

yesvee said:
I tried to use HTML::pager to display my database contents. The
contents are displayed but navigation doesnot work. I have given my
code below.

You are misunderstanding the proper use of this module. It does not
automatically pull only current page's results out of the results
array. Instead, your handler gets passed two values - the current
start (offset), and the number of rows per page. Your handler then
uses these values to determine what to put into the results array.
#!/usr/bin/perl

#uses
use strict;
use warnings;

VERY GOOD!!
use diagnostics;
use DBI;
use CGI;
use HTML::pager;

#Declare Variables
my $query=CGI->new();
my $count=0;

#Fetch DB Connects

my $get_data_sub = sub {

my ($offset, $per_page) = @_;
my (@return_array,@data);

#connect db & prepare stmt
my $dbHandle =
DBI->connect("dbi:mysql:tempdb","user","password") or die ("Cannot
Connect to database");
my $stmtHandle = $dbHandle->prepare("select sno,name,age,deptno
from sample1");

my $stmtHandle = $dbHandle->prepare(<<EO_SQL);
SELECT sno, name, age, deptno
FROM sample1
LIMIT $offset, $per_page
EO_SQL

[remainder snipped]

For more information, read the documentation for the module you're
using:
http://search.cpan.org/~samtregar/HTML-Pager-0.03/Pager.pm

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top