diff --git a/resources/paging.php b/resources/paging.php index 8b927f2af1..a5f649bc70 100644 --- a/resources/paging.php +++ b/resources/paging.php @@ -17,14 +17,14 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2018 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ -function paging($num_rows, $param, $rows_per_page, $mini = false) { +function paging($num_rows, $param, $rows_per_page, $mini = false, $result_count = 0) { //add multi-lingual support @@ -32,7 +32,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false) { $text = $language->get(); //default number of rows per page - if (strlen($rows_per_page)==0) { + if (strlen($rows_per_page) == 0) { $rows_per_page = 50; } @@ -47,8 +47,10 @@ function paging($num_rows, $param, $rows_per_page, $mini = false) { // counting the offset $offset = ($page_number - 1) * $rows_per_page; - // how many pages we have when using paging? - $max_page = ceil($num_rows/$rows_per_page); + // how many pages we have when using paging + if ($num_rows > 0) { + $max_page = ceil($num_rows/$rows_per_page); + } // print the link to access each page $self = $_SERVER['PHP_SELF']; @@ -61,6 +63,7 @@ function paging($num_rows, $param, $rows_per_page, $mini = false) { $nav .= " $page \n"; } } + if ($page_number > 0) { $page = $page_number - 1; $prev = "\n"; //◀ @@ -74,12 +77,15 @@ function paging($num_rows, $param, $rows_per_page, $mini = false) { $page = $page_number + 1; $next = "\n"; //▶ $last = "\n"; //▼ - } else { $last = "\n"; //▼ - $next = "\n"; //▶ + $next = "\n"; //▶ + } + //if the result count is less than the rows per page then this is the last page of results + if ($result_count > 0 and $result_count < $rows_per_page) { + $next = "\n"; //▶ } $array = array(); @@ -123,7 +129,22 @@ function paging($num_rows, $param, $rows_per_page, $mini = false) { "}\n". "\n"; //determine size - $code = ($mini) ? $prev.$next."\n".$script : "
".$prev."     ".$max_page."    ".$next."
\n".$script; + if ($mini) { + $code = $prev.$next."\n".$script; + } + else { + $code .= "
"; + $code .= " ".$prev; + $code .= "    "; + $code .= " "; + if ($result_count == 0) { + $code .= "   ".$max_page.""; + } + $code .= "    "; + $code .= " ".$next; + $code .= "
\n".$script; + } + //add to array $array[] = $code; }