Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

split large flatfile into numbered pages?

Status
Not open for further replies.
Apr 13, 2006
9
GB
Hey,

Can anyone explain to me how i can take all the info from a flatfile but split it into pages??. For example I have a file containing a list of 1000 games(line by line), instead of having all 1000 displayed on the screen at the same time..how can i split it into say pages with 100 games on each?.

output example: It displays the first 100 lines from the flatfile and then when i click page 2 it displays the next 100..and so on.

 
You can use the query string to provide a "start" value, like "list.cgi?start=200" and go on a for loop through the array to get a list of just the ones you want to show.

Code:
my $start = $cgi->param ('start');
my $end = $start + 100;

my @showOnPage = ();
for (my $i = $start; defined $gameArray[$i] && $i <= $end; $i++) {
   push (@showOnPage, $gameArray[$i]);
}

# @showOnPage now would contain, say,
# games 200 to 300 from the array
# @gameArray

You could then check the positions of the previous and next positions in @gameArray to determine if a "Previous Page" or "Next Page" link should be used, or divide up the scalar(@gameArray) to get a list of actual page numbers you could link to.
 
It's a little more complicated then that if you want the next/prev/page-number links on the page to click on. But you could use Kirsle's code to build a page break routine on. There are a couple of modules that create page breaks but you would need to install them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top