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: [Laurent_R] Another way besides using ceil?: Edit Log



hwnd
User

Mar 31, 2013, 3:43 PM


Views: 640
Re: [Laurent_R] Another way besides using ceil?

Ok let's see. I'll break this down a bit.


Code
   

# Page we are on ( e.g. ?id=1;use=10 )

my $page_id = param('id') || 1;



# Records we want to use per page (default 10)

my $per_page = param('use') || 10;



# Calling the sub routine from package module

my ($curr, $total) = $dbh->page_count("dbtablename", $page_id, $per_page);



# sub routine in package module

sub page_count {

my ($self, $tbl, $pg_id, $per_page) = @_;

my $dbh = $self->dbh();

my $sth = $dbh->selectrow_arrayref("SELECT COUNT(*) FROM $tbl");

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

my $total = int($sth->[0] / $per_page) + 1;

return ($curr, $total);

}



Say we have 40 records total, it indexes through the script showing results (e.g ?id=1;use=10, ?id=11;use=10, ?id=21;use=10, and so on. )

So for how I am doing this if I put ?id=1;use=40 it indexes page (1 of 2) with only being one page


(This post was edited by hwnd on Mar 31, 2013, 3:45 PM)


Edit Log:
Post edited by hwnd (User) on Mar 31, 2013, 3:45 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