# Count how many rows are there in a table, so that we can use it for $pagenum. my $sql = qq!SELECT COUNT(*) from "Orders" !; my $sth = $dbh->prepare ("$sql"); $sth->execute() || quit(); my @row = $sth->fetchrow_array; $sth->finish; # Setting offset, limit and page number my $offset = 0; my $limit = 8; my $pagenum = ceil($row[0]/$limit); # Assigning value to $offset as 0 or whatever will be the $pagenum i.e. 1 or 2 .... $offset=param('page')? $limit*param('page') :0; # Get the data $sql = qq!SELECT a."OrderID", b."CompanyName" AS "CustomerName", c."FirstName"::text || ' ' ||c."LastName"::text AS "EmployeeName", a."OrderDate"::DATE, a."RequiredDate"::DATE, a."ShippedDate"::DATE, d."CompanyName" AS "ShipVia", a."Freight", a."ShipName", a."ShipAddress", a."ShipCity", 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 LIMIT $limit OFFSET $offset !; $sth=$dbh->prepare("$sql"); $sth->execute() || quit(); .... then html stuff skiped.... # Showing page number with link my $first_page = $pagenum - $pagenum ; my $last_page = $pagenum - 1; $pagenum = $pagenum - 1; print q();