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

Splitting stuff into many pages with back and next buttons - (Was: Max Submissions?)

by bjelli (Pilgrim)
on Sep 06, 2001 at 16:51 UTC ( #110555=note: print w/replies, xml ) Need Help??

in reply to Max Submissions?

Perl won't do this for you automatically, you have to program it. I agree with chadys advice, storing the entries in a database of some sort would be better than just storing the html.

anyways, here's what you can do with your version of the program:

You need to keep track of when it's time to write a new file. That means you need a counter of some sort. You'll have to store the counter in a different file again, maybe counter.txt.

open(C, "counter.txt") and $c = <C> and close C and $c++; open(C, ">counter.txt") and print C $c and close C;

Let's say you want to start a new file every time the counter reaches a multiple of 10. You might call the files that contain the html "view0.htm" for the first 10 entries, "view1.htm" for the next 10, and so on.

$fileno = int($c / 10); $filename = "view" . $fileno . ".htm"; open(DASH,">>$filename"); print DASH "print the entry here"; close DASH

That's almost all. If you want to have Links from one page of the guestbook to the next, you have two options: do it in HTML, with frames (yuck, I hate frames) or write the links into the view*.htm files. Putting the "back" at the top of each page:

if (int($c / 10) == $fileno ) { # this is the first time we write to this # file, because $c is 10 or 20 or 30 or ... # link back to the one before print DASH "<a href=view" . ($fileno-1) . ".htm>Back</a>"; }
and the "Next" link at the bottom is probably the easiest:
if ( $c % 10 == 9 ) { # this is the last time we write to this # file, because $c is 9 or 19 or 29 or 39 or ... # link on to the next one print DASH "<a href=view" . ($fileno+1) . ".htm>Next</a>"; }

Assembling these code snippets in the right order is left as an exercise to the student ;-)

Brigitte    'I never met a chocolate I didnt like'    Jellinek

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://110555]
[LanX]: AnomalousMonk: yeah the asteroid but not the god, right?
[jedikaiti]: :-)
[AnomalousMonk]: LanX: Of course the asteroid! There is/are no god(s).

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (16)
As of 2017-11-22 17:13 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (327 votes). Check out past polls.