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: Re: [terrykhatri531] Need help to improve pagination: Edit Log


Aug 2, 2014, 8:37 AM

Views: 35392
Re: [terrykhatri531] Need help to improve pagination

I think I now understand your concept, but its totally unnecessary. The image you attached shows that the script has been passed the parameter page=15. You need to set the currentPage option of the pagination plugin to this value. Its as simple as that, just as my example above entails, play with the demo I linked to, look at url query string and compare with the source code etc.

If you require any further help from us Perl guys, please post all relevant code.

Finally, for reference, here is a more complete version of my example above. It uses Data::Page to do all the core calculations then passes whats necessary to the plugin. It is a lot more forgiving under race conditions and we can fetch the resultset without any additional work. This is the beginnings of a pure Data::Page solution.

use strict;
use warnings;
use CGI::Carp qw/fatalsToBrowser/;
use CGI;
use Data::Page;
use HTML::Template;

my $items = 100;

my $cgi = CGI->new;

my $items_on_page = $cgi->param('items_on_page');
my $current_page = $cgi->param('current_page');

$items_on_page = 10 unless ($items_on_page =~ m/^[1-9]\d*$/);

my $page = Data::Page->new;


my $offset = $page->first;
my $limit = $page->entries_on_this_page;
my $info = 'page: ' . $page->current_page . ', first: ' . $page->first . ', last: ' . $page->last . ', offset: ' . $offset . ', limit: ' . $limit;

my $template = HTML::Template->new(filehandle => \*DATA);

$template->param(pages => $page->last_page);
$template->param(current_page => $page->current_page);
$template->param(items_on_page => $page->entries_per_page);
$template->param(info => $info);

print $cgi->header, $template->output;

<script type="text/javascript" language="javascript" src=""></script>
<script type="text/javascript" language="javascript" src=""></script>
<script type="text/javascript" language="javascript">
pages: <TMPL_VAR NAME=pages>,
currentPage: <TMPL_VAR NAME=current_page>,
hrefTextPrefix: '<TMPL_VAR NAME=items_on_page>&current_page=',

<link type="text/css" rel="stylesheet" href=""/>
<p><TMPL_VAR NAME=info>.</p>
<div class="mypagination">
<p>error loading pagination.</p>



(This post was edited by Zhris on Aug 2, 2014, 8:40 AM)

Edit Log:
Post edited by Zhris (Enthusiast) on Aug 2, 2014, 8:37 AM
Post edited by Zhris (Enthusiast) on Aug 2, 2014, 8:40 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