From 09765b9627a721ecd514027be052a85fcc9b4b47 Mon Sep 17 00:00:00 2001 From: Ruan Date: Sun, 19 Jul 2015 09:48:32 +0200 Subject: [PATCH] Add total page count, fix offsets --- bans.php | 2 +- includes/page.php | 24 ++++++++++++++++++------ mutes.php | 2 +- warnings.php | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bans.php b/bans.php index 21b3c0f..807c6c8 100644 --- a/bans.php +++ b/bans.php @@ -37,7 +37,7 @@ $page = new Page(); - print_pager("bans.php"); ?> + print_pager("bans.php", $page->settings->table_bans); ?> print_footer(); ?> diff --git a/includes/page.php b/includes/page.php index fe40c15..eb0e8cd 100644 --- a/includes/page.php +++ b/includes/page.php @@ -10,7 +10,7 @@ class Page { $this->settings = $settings; $this->uuid_name_cache = array(); $this->time = microtime(true); - $this->page = 0; + $this->page = 1; if (isset($_GET['page'])) { $page = $_GET['page']; // user input @@ -27,7 +27,8 @@ class Page { $offset = 0; if ($this->settings->show_pager) { - $offset = ($limit * $this->page); + $page = $this->page - 1; + $offset = ($limit * $page); } $query = "SELECT * FROM $table $active_query GROUP BY $table.id ORDER BY time DESC LIMIT :limit OFFSET :offset"; $st = $this->conn->prepare($query); @@ -123,17 +124,28 @@ class Page { '); } - function print_pager($page) { + function print_pager($page, $table) { if (!$this->settings->show_pager) return; - $prev = $this->page - 1; + $result = $this->conn->query("SELECT COUNT(*) AS count FROM $table")->fetch(PDO::FETCH_ASSOC); + $total = $result['count']; + + $pages = (int)($total / $this->settings->limit_per_page) + 1; + + $cur = $this->page; + $prev = $cur - 1; $next = $this->page + 1; $pager_prev = "
«
"; if ($this->page > 0) { $pager_prev = "$pager_prev"; } - $pager_next = "
»
"; - echo "$pager_prev $pager_next"; + + $pager_next = "
»
"; + if ($cur < $pages) { + $pager_next = "$pager_next"; + } + $pager_count = "
Page $cur/$pages
"; + echo "$pager_prev $pager_next $pager_count"; } function print_footer() { diff --git a/mutes.php b/mutes.php index 1439928..8575d79 100644 --- a/mutes.php +++ b/mutes.php @@ -36,7 +36,7 @@ $page = new Page(); - print_pager("mutes.php"); ?> + print_pager("mutes.php", $page->settings->table_mutes); ?> print_footer(); ?> diff --git a/warnings.php b/warnings.php index ab6560f..9314bf9 100644 --- a/warnings.php +++ b/warnings.php @@ -38,7 +38,7 @@ $page = new Page(); - print_pager("warnings.php"); ?> + print_pager("warnings.php", $page->settings->table_warnings); ?> print_footer(); ?>