From 8414843bbfd3140660e281809107cc7f17b5a852 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 14 Jul 2022 16:45:17 +0200 Subject: [PATCH] Prevent current page from being 0 if no items are present --- models/GenericTable.php | 2 +- models/PageIndex.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/GenericTable.php b/models/GenericTable.php index df54bda2..0da224c9 100644 --- a/models/GenericTable.php +++ b/models/GenericTable.php @@ -43,7 +43,7 @@ class GenericTable $this->start = empty($options['start']) || !is_numeric($options['start']) || $options['start'] < 0 || $options['start'] > $this->recordCount ? 0 : $options['start']; // Figure out where we are on the whole, too. - $numPages = ceil($this->recordCount / $this->items_per_page); + $numPages = max(1, ceil($this->recordCount / $this->items_per_page)); $this->currentPage = min(ceil($this->start / $this->items_per_page) + 1, $numPages); // Let's bear a few things in mind... diff --git a/models/PageIndex.php b/models/PageIndex.php index 6033c9a5..0c988ccf 100644 --- a/models/PageIndex.php +++ b/models/PageIndex.php @@ -63,9 +63,9 @@ class PageIndex lower current/cont. pgs. center upper */ - $this->num_pages = ceil($this->recordCount / $this->items_per_page); + $this->num_pages = max(1, ceil($this->recordCount / $this->items_per_page)); $this->current_page = min(ceil($this->start / $this->items_per_page) + 1, $this->num_pages); - if ($this->num_pages == 0) + if ($this->num_pages <= 1) { $this->needsPageIndex = false; return;