Here is the script that needs pagination :
#!/usr/local/bin/perl
use DBI;
use CGI;
use strict;
use HTML::Template;
my $CGI = CGI->new();
my $dbh = dbh(); # connect to db
$dbh->do("SET search_path to northwind") or die;
# grab the stuff from the database
my $sql = qq!SELECT
a."OrderID", b."CompanyName" AS "CustomerName",
c."FirstName"::text || ' ' ||c."LastName"::text AS "E
+mployeeName",
a."OrderDate", a."RequiredDate", a."ShippedDate", d."
+CompanyName" AS "ShipVia",
a."Freight", a."ShipName", a."ShipAddress", a."ShipCi
+ty", a."ShipRegion",
a."ShipPostalCode", a."ShipCountry"
FROM
"Orders" a, "Customers" b, "Employees" c, "Shippers"
+d
WHERE
a."CustomerID" = b."CustomerID" AND
a."EmployeeID" = c."EmployeeID" AND
a."ShipVia" = d."ShipperID"
ORDER BY 1 !;
my $sth = $dbh->prepare($sql);
$sth->execute();
# prepare a data structure for HTML::Template
my $rows;
push @{$rows}, $_ while $_ = $sth->fetchrow_hashref();
# instantiate the template and substitute the values
my $template = HTML::Template->new(filename => 'Orders.tmpl');
$template->param(ROWS => $rows);
print $CGI->header();
print $template->output();
$dbh->disconnect();
# connect to database
sub dbh {
my $dsn = 'DBI:Pg:dbname=northwind;host=localhost';
my $user = 'postgres';
my $pwd = 'postgres';
my $dbh = DBI -> connect($dsn,$user,$pwd,{'RaiseError' => 1});
return $dbh;
}
If you need the template code used in this script I will post it.
Many thank !!! |