Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: displaying 10 results per page

by poj (Prior)
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://972710]
help
Chatterbox?
[msh210]: About time... last time I was right was... I don't even remember when.
[shmem]: perl -e 'warn "test$/", ^@^ '
[Eily]: well, at least it's right about warn doing the same thing as die :)
[shmem]: same with undef as last element
[msh210]: oh, good point. It's the best kind of correct
[shmem]: msh210: but I'd not call it a lie outright. That's when you do know the truth.
[msh210]: I don't have sendmail (I'm on MS Windows), so does one of you think you can report the bug?
[shmem]: msh210: 'tis about time to tell the sad truth to perl5porters - via perlbug
[msh210]: probably whoever wrote that actually knows the truth
[shmem]: msh210: you can save the perlbug text in a file and send that via your mail agent of choice

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2017-04-24 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (439 votes). Check out past polls.