in reply to Perl Database Paging
my $result_count = (however you want to get a total result count); if (!$page) {$page = '0'} my $offset = ($page * $max_page_results ); my $high_offset = ($offset + $max_page_results); my $total_pages = (ceil($result_count / $max_page_results) - '1'); my $next_page = ($page + '1'); my $previous_page = ($page - '1'); my $starting_page = ($page - '2'); #Setting limits to 0 and high page count if ($high_offset > $result_count) {$high_offset = $result_count;} if ($page == '0' ) {$previous_page = '0';} if ($next_page >= $total_pages) { $next_page = $total_pages; } #Displays 5 Page buttons at a time my @page_arr; my $ending_page = ($page + '2'); if ($starting_page < '0') {$starting_page = '0'; } if ($ending_page < '4') {$ending_page = ('4' - $starting_page);} if ($ending_page > $total_pages){$ending_page = $total_pages;} for my $i($starting_page..$ending_page){ push @page_arr, $i ;} #Results Display print '<div id="device-browse-all-display">'; print qq{ <div class="row"> <div class="col-sm-3"> <nav> <ul class="pagination"> <li> <a href="$ENV{'SCRIPT_NAME'}?page=$previous_page" ari +a-label="Previous"> <span aria-hidden="true">«</span> </a> < +/li>}; foreach my $page_link(@page_arr) { if ($page_link == $page) { print qq{<li class="active"><a href +="$ENV{SCRIPT_NAME}?page=$page_link">$page_link <span class="sr-only" +>(current)</span></a></li>}; } else { print qq{ <li><a href="$ENV{SCRIPT_NAME}?page=$p +age_link">$page_link </a> </li>}; } } print qq{<li> <a href="$ENV{SCRIPT_NAME}?page=$next_page" aria-lab +el="Next"> <span aria-hidden="true">»</span> </a> </li>};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Database Paging
by Anonymous Monk on Apr 28, 2017 at 14:14 UTC |