Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: displaying 10 results per page

by poj (Priest)
on May 27, 2012 at 14:19 UTC ( #972710=note: print w/ replies, xml ) Need Help??


in reply to Re^2: displaying 10 results per page
in thread displaying 10 results per page

I'm not sure what the while loop is for if you only want to show one page. Here is slightly refactored code with it removed.

sub browse_ten { # work out how many users my @users = glob("users_dir/*"); my $no_of_users = scalar(@users); # calculate how many pages to display my $page_last = ceil($no_of_users / 10) ; # get page to show from param or default 1 my $page_show = param('page') || 1; my $page_prev = $page_show - 1; my $page_next = $page_show + 1; # decide whether to show links print h2("Page $page_show of $page_last"); # optional if ($page_show > 1) { # Show a Previous link print a({href => "?page=$page_prev"},"Previous"); } if ($page_show < $page_last) { # Show a Next link print a({href => "?page=$page_next"},"Next"); } # calc start and end user index number starting # page 1 user start is 0, page 2 is 10 # page 1 end is start + 9 unless on last page my $user_start = ($page_show - 1) * 10; my $user_end = ($page_show < $page_last) ? $user_start + 9 : $no_of_ +users - 1 ; # Show the range of entries. for my $i ($user_start .. $user_end) { my $user_to_show = $users[$i]; # user image my $img_src = "$user_to_show/image.jpg"; unless (-r $img_src){ $img_src = 'blank_profile.jpg'; } print img({src =>$img_src, width=>150, height=> 150 }); # user profile my $profile_filename = "$user_to_show/profile"; if (open my $p, $profile_filename){ my $profile = join '<br/>', <$p>; close $p; print $profile; } else { print "Can not open $profile_filename : $!"; } print br; } }
poj


Comment on Re^3: displaying 10 results per page
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-11-26 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (176 votes), past polls