#/usr/bin/perl -w use strict; use DBI; use CGI ':standard'; #use CGI::Carp 'fatalsToBrowser'; # constants my $locn = 'Phoenix, AZ USA'; my $pagesize = 5; # variables my $LastName = param('LastName'); my $reqpage = param('reqpage') || 1; my $name_like = substr($LastName,0,3).'%'; # connect to database my $dbh = get_dbh(); # get record count # calc page count and offset my $rec_count = rec_count(); my $page_count = int($rec_count / $pagesize); ++$page_count if ($rec_count % $pagesize); my $offset = ($reqpage-1) * $pagesize; # start page print header,start_html( -title=>'PAGE TITLE', -style=>{ -code=>'margin-top: 0px; margin-left: 0px; margin-right: 0px;'} ); # simple form for testing print qq!
!; # search results results(); # page links print page_links() if $page_count > 1; debug(); print end_html(); # return count sub rec_count { my $sql = "SELECT count(*) from members WHERE (Location = ? and LastName LIKE ?)"; my $rec_count = $dbh->selectrow_array($sql,undef,$locn,$name_like); return $rec_count; } # search result sub results { my $sql = qq! SELECT ID,LastName,Location FROM members WHERE (Location = ? and LastName LIKE ?) LIMIT ?,?!; my $sth=$dbh->prepare($sql); $sth->execute($locn,$name_like,$offset,$pagesize); my $table = qq!ID | LastName | Location |
$f[0] | $f[1] | $f[2] |
LastName = |$LastName| reqpage = $reqpage rec_count = $rec_count pagesize = $pagesize page_count = $page_count offset = $offset! }