Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^14: Need help with pagination

by *alexandre* (Scribe)
on Jan 02, 2023 at 05:04 UTC ( [id://11149271]=note: print w/replies, xml ) Need Help??


in reply to Re^13: Need help with pagination
in thread Need help with pagination

HI thanks for your time : I made some change to make to code more readable :
#!c:/xampp/perl/bin/perl.exe use warnings; use CGI; use Time::HiRes qw(gettimeofday); my $query = CGI->new; my $dir = "C:/Users/41786/OneDrive/Documents/recordz1/"; print $query->header; test(); sub test { my $counter = 1000; #Should be get from db; my $string = ""; my $first_page = 0; my $min_index = $query->param("min_index"); if ($min_index = '') { $min_index = 0; } open (FILE, "<$dir/test2.html") or die "cannot open file $dir/test +2.html"; my $content = ""; my $max_index = $query->param("max_index"); if ($max_index = '') { $max_index = 40; }else { $max_index = round ($counter / 40, 1);#Number of objects displ +ayed per page. } my $last_page = $nb_page - 1; my $n2 = 0; my $count_per_page = 10; my $index_page = 0; for my $index (0..$max_index) { $next_page = $min_index + 40; if ($index < $count_per_page) { if (($index % $count_per_page) > 0) { $string .= "<a href=\"/cgi-bin/pagination.pl?lang=FR&a +mp;session=1;min_index=$min_index&amp;max_index=$max_index\" ><-$inde +x_page-></a>&#160;&nbsp;"; } } $index_page++; $min_index += 40;; } $string .= "<a href=\"/cgi-bin/pagination.pl?lang=FR&amp;session=1 +;min_index=$min_index&amp;max_index=$max_index\" ><-\"Next\"-></a>&#1 +60;&nbsp;"; while (<FILE>) { s/\$ARTICLE{'index'}/$string/g; $content .= $_; } print $content; close (FILE); } sub round { my $n = shift || ''; my $r = sprintf("%.0f", $n); return $r; }
Now I have the following output : <-1-> <-2-> <-3-> <-4-> <-5-> <-6-> <-7-> <-8-> <-9-> <-"Next"-> Thx for kind help.

Replies are listed 'Best First'.
Re^15: Need help with pagination
by Corion (Patriarch) on Jan 02, 2023 at 07:18 UTC

    Again, please answer the following questions:

    What is the error you see?

    What is the output you get?

    What is the output you expect?

    I'm asking these questions since I don't know what you think is wrong with your code.

      Hi I don't get any errors anymore with the pagination here is the full sample script
      #!c:/xampp/perl/bin/perl.exe use warnings; use CGI; use Time::HiRes qw(gettimeofday); my $query = CGI->new; my $dir = "C:/Users/41786/OneDrive/Documents/recordz1/"; print $query->header; test(); sub test { my $counter = 1000; #Should be get from db; my $string = ""; my $first_page = 0; my $nb_page = 0; my $min_index = $query->param("min_index"); if (not defined $min_index) { $min_index = 0; } my $count_per_page = 10; open (FILE, "<$dir/test2.html") or die "cannot open file $dir/test +2.html"; my $content = ""; my $max_index = $query->param("max_index"); if (not defined $max_index) { $max_index = 40; } else { #$max_index = round ($counter / 40, 1);#Number of objects disp +layed per page. } my $last_page = $nb_page - 1; my $n2 = 0; my $index_page = $query->param("index_page"); if (not defined $index_page) { $index_page = 0; } my $previous_page = $query->param("previous_page"); if (not defined $previous_page) { $index_page = 0; $previous_page = 0; } my $index = 0; $string .= "<a href=\"/cgi-bin/pagination.pl?lang=FR&amp;session=1 +\" ><-\"First page\"-></a>&#160;&nbsp;"; if (($index_page -1) > 0) { $previous_page = $previous_page - 1; $index_page--; $index--; $min_index = $min_index -40; $max_index = $max_index -40; $string .= "<a href=\"/cgi-bin/pagination.pl?lang=FR&amp;sessi +on=1;min_index=$min_index&amp;max_index=$max_index&amp;previous_page= +$previous_page&amp;index_page=$index_page\" ><-\"Previous\"-></a>&#16 +0;&nbsp;"; } for my $index ($min_index..$max_index) { $next_page = $min_index + 40; if ($index_page < $count_per_page) { if (($index_page % $count_per_page) > 0) { + $string .= "<a href=\"/cgi-bin/pagination.pl?lang=FR&a +mp;session=1&amp;min_index=$min_index&amp;max_index=$max_index&amp;in +dex_page=$index_page&amp;previous_page=$previous_page&amp;index_page= +$index_page\" ><-$index_page-></a>&#160;&nbsp;"; } } $index_page++; $index++; $min_index += 40;; $max_index += 40;; } $string .= "<a href=\"/cgi-bin/pagination.pl?lang=FR&amp;session=1 +;min_index=$min_index&amp;max_index=$max_index&amp;previous_page=$pre +vious_page\" ><-\"Next\"-></a>&#160;&nbsp;"; while (<FILE>) { s/\$ARTICLE{'index'}/$string/g; $content .= $_; } print $content; close (FILE); } sub round { my $n = shift || ''; my $r = sprintf("%.0f", $n); return $r; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11149271]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-19 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found