CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [hwnd] Another way besides using ceil?: Edit Log



hwnd
User

Apr 1, 2013, 3:57 PM


Views: 621
Re: [hwnd] Another way besides using ceil?

This seems to work if I use a modulos operator.


Code
   

my $pg_curr = int($pg_id / $per_page)+1;

my $pg_total = int($sth->[0] / $per_page);

++$pg_total if ($sth->[0] % $per_page);

Or this would work also:

Code
 
my $total_recs = $dbh->selectrow_array("SELECT COUNT(*) FROM table");



my $count = 0;

for (my $first = 1; $first <= $total_recs; $first += $per_page)

{

$count++;

my $last = $first + $per_page - 1;

$last = $total_recs if $last > $total_recs;



my $label = $count;

my $link;



if ($first != $start) {

my $url = sprintf ("%s?start=%d;per_page=%d",url(),$first,$per_page);

$link = a ({-href => $url}, $label);

} else {

$link = $label;

}

print "[$link] ";

}



(This post was edited by hwnd on Apr 1, 2013, 10:07 PM)


Edit Log:
Post edited by hwnd (User) on Apr 1, 2013, 10:07 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives