my $perpage = '25'; my $curpage = $q->param('curpage') || 1; # Assumes $q is a CGI object my $custno = $q->param('custno'); my $offset = $curpage*$perpage; my $orderby = 'partno'; my $totalcount = @{ $dbh->selectrow_arrayref( qq{SELECT count(*) FROM parts WHERE custno = '$custno'} ) }[0]; # Next four lines limit the results of the LAST page's data, in case of a short page. my $reccount = $perpage; if (($totalcount - $offset) < 0) { $reccount = $totalcount-$offset+$perpage; } # Now build the select (read inside out) (my $select = <selectall_arrayref($select,{Columns=>{}}) || die 'Whoops!';