CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: [SOLVED] Need help to improve pagination: Edit Log


Jul 21, 2014, 7:03 AM

Views: 36249
[SOLVED] Need help to improve pagination


I have created pagination using the following code it works but does not look graceful as it displays links for all 103 pages what I need help for is to make it compact like : [First][Prev][1][2][3][4][5][6]...[103][Next][last] the way its shown in the attached picture, I have looked at perl pagination modules @ cpan but there aren't enough examples for a guy of my level to use them.

# 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;

# 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"
"Orders" a, "Customers" b, "Employees" c, "Shippers" d
a."CustomerID" = b."CustomerID" AND
a."EmployeeID" = c."EmployeeID" AND
a."ShipVia" = d."ShipperID"
LIMIT $limit OFFSET $offset !;

$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(<ul class="tsc_pagination tsc_paginationA tsc_paginationA09">);
print qq(<li><a href='$first_page'>First</a></li>);
for my $i (0 .. $pagenum)
print qq(<li><a href='$i'>$i</a></li>);
print qq(<li><a href='$last_page'>Last</a></li>);
print q(</ul>);

I have also attached a jquery plugin which I believe can be integrated with my code but I don't have a clue how, it shows how a light compact pagination may look with the js script, which you experienced gurus can understand.

Your help as usual will be much appreciated.

Many thanks !


(This post was edited by terrykhatri531 on Aug 8, 2014, 8:59 AM)
Attachments: How I want.png (2.28 KB)
  My Pagination.png (21.8 KB) (5.54 KB)

Edit Log:
Post edited by terrykhatri531 (User) on Jul 21, 2014, 7:07 AM
Post edited by terrykhatri531 (User) on Jul 21, 2014, 8:17 AM
Post edited by terrykhatri531 (User) on Aug 8, 2014, 8:59 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives