Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: last 10 ... next 10?

by epoptai (Curate)
on Mar 28, 2001 at 22:33 UTC ( [id://67894]=note: print w/replies, xml ) Need Help??


in reply to last 10 ... next 10?

You need to keep track of two things: where to start, and how many to show.

First set $start to one unless we're getting a param.

unless(param('start')){ $start = 1 }
Then use two counters to track where to start and how many to process.
for(@array){ $c++; # count all items if($c >= $start){ # if $c count is = or greater than where to star +t $d++; # count items that match first test unless($d > $show){ # unless $d count is greater than how many + to show print # or whatever } } }
Then calculate the 'previous n' and 'next n' links.
$previous = ($start-$show); unless($previous < 1){ # unless we're already at the beginning print qq~<a href="$url?start=$previous&show=$show"> Previous $show</a>~; } $next = ($start+$show); unless($next > $c){ # unless we're already at the end print qq~<a href="$url?start=$next&show=$show"> Next $show</a>~; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found