Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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
http://www.horus.com/~bjelli/         http://perlwelt.horus.at


Comment on Splitting stuff into many pages with back and next buttons - (Was: Max Submissions?)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-01-25 04:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My top resolution in 2015 is:

















    Results (180 votes), past polls