4 unless (exists($opt{'count_query'}) && length($opt{'count_query'})) {
5 ( $opt{'count_query'} = $opt{'query'} ) =~
6 s/^\s*SELECT\s*(.*)\s+FROM\s/SELECT COUNT(*) FROM /i;
9 my $conf = new FS::Conf;
10 my $maxrecords = $conf->config('maxsearchrecordsperpage');
12 my $limit = $maxrecords ? "LIMIT $maxrecords" : '';
14 my $offset = $cgi->param('offset') || 0;
15 $limit .= " OFFSET $offset" if $offset;
17 my $count_sth = dbh->prepare($opt{'count_query'})
18 or die "Error preparing $opt{'count_query'}: ". dbh->errstr;
20 or die "Error executing $opt{'count_query'}: ". $count_sth->errstr;
21 my $total = $count_sth->fetchrow_arrayref->[0];
23 my $sth = dbh->prepare("$opt{'query'} $limit")
24 or die "Error preparing $opt{'query'}: ". dbh->errstr;
26 or die "Error executing $opt{'query'}: ". $sth->errstr;
28 #can get # of rows without fetching them all?
29 my $rows = $sth->fetchall_arrayref;
33 <% my $pager = include ( '/elements/pager.html',
35 'num_rows' => scalar(@$rows),
37 'maxrecords' => $maxrecords,
41 <%= $total %> total <%= $opt{'name'} %><BR><BR><%= $pager %>
42 <%= include( '/elements/table.html' ) %>
44 <% foreach ( @{$sth->{NAME}} ) { %>
48 <% foreach my $row ( @$rows ) { %>
50 <% foreach ( @$row ) { %>