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 !!!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.