有一段时间以来,我一直在寻找适合我的分页问题的解决方案,我的以下perl脚本确实有效,但它创建了数百个页面链接,看起来非常奇怪,我需要一个紧凑的,为此我遇到了一个网站这提供了我正在寻找的解决方案,但帮助非常少,我不是一个jquery人,我一直在谷歌搜索我是否可以自己使用这个jquery脚本,但找不到有用的提示,因此我在OverFlow到这里寻求您的帮助,将此jquery插件与我的代码集成。
Here是我上面提到的jquery代码和演示。
如果您现在知道jquery但没有时间,请在有空的时候将其标记出来,但是请帮忙,我在这里看到了专家提供的代码。
这是我的剧本:
# 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>);
非常感谢!!
答案 0 :(得分:2)
首先声明:
my $reqpage = $q->param('reqpage') || '1';
然后在脚本的正文部分添加以下内容:
<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>