Home : General : Perl Programming :

General: Perl Programming: Re: [Wil] Text files, directories, back and next buttons.: Edit Log

Here is the list of edits for this post
Re: [Wil] Text files, directories, back and next buttons.
How's this Wil?

Code:
sub span {
my ($hits, $limit, $max, $span) = (shift, 8, $per_page, "");
my $half = $limit / 2;
my $total = int(($hits/$max) + 1);
die "invalid page" if ($page > $total);
my $start = ($page > $half) ? ($page - $half) : (1);
my $finish = ($page + $half > $total) ? ($total) : ($page + $half);
my $i = ($finish - $start);
(($finish - $page < $page - $start) ? ($start += $i - $limit) : ($finish += $limit - $i)) if (($i < $limit) and ($limit < $total));
$span .= ($page != 1) ? &link(1, "&lt;&lt;") . &link(($page - 1 or 1), "&lt;") : qq|&lt;&lt; &lt; |;
($span .= ($_ == $page) ? "[$_] " : &link($_)) for ($start .. $finish);
$span .= ($page != $total) ? &link($page + 1, "&gt;", "next") . &link($total, "&gt;&gt;") : qq|&gt; &gt;&gt; |;
return $span;
}

sub link {
my ($p, $d) = @_;
$d ||= $p;
return qq|<a href="query.cgi?$string&pg=$p">$d</a> |;
}

(note that this code is from my search engine and won't work in the file browsing script posted earlier)

--Philip
Links 2.0 moderator

Last edited by:

King Junko II: Mar 20, 2002, 3:09 AM

Edit Log: