Reputation: 199
For sometime I have been looking for an adequate solution to my pagination woes, my following perl script does work however it creates page links in hundreds which looks very odd, I need a compact one and for this I have come across a site which provides the solution I am looking for but the help is very scanty and I am not a jquery person, I have been googling around to see if I can use this jquery script myself but could not find helpful hints therefore I am here at OverFlow to seek your assistance in integrating this jquery plugin with my code.
Here is the jquery code and demo that I mentioned above.
If you know jquery but don't have time right now, please mark it for later when you have time, but please do help, I have seen threads here full of codes provided by you experts.
Here is my script:
# 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(<ul class="tsc_pagination tsc_paginationA tsc_paginationA09">);
print qq(<li><a href='vieword.pl?page=$first_page'>First>);
for my $i (0 .. $pagenum)
{
print qq(<li><a href='vieword.pl?page=$i'>$i>);
}
print qq(<li><a href='vieword.pl?page=$last_page'>Last>);
print q(</ul>);
Many many thanks !!
Upvotes: 0
Views: 172
Reputation: 633
First declare :
my $reqpage = $q->param('reqpage') || '1';
and then add the following in the body section of your script :
<script src="js/jquery.paginate.js" type="text/javascript"></script>
<script type="text/javascript">
\$(function() {
\$("#demo2").paginate({
count : $your_page_count,
start : $reqpage,
onChange : function(reqpage) {
location.href = 'your_script.pl?reqpage='+ reqpage;},
display : 27,
border : false,
text_color : '#303030',
background_color : '#EEE',
text_hover_color : 'black',
background_hover_color : '#CFCFCF'
});
});
</script>
Upvotes: 2