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 '