From 770f21f5e15f3e505c18c9a1aced826b75dca319 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 20 Jun 2018 03:36:44 +0100 Subject: [PATCH] lib/php/db/table.php --- lib/php/db/table.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/php/db/table.php b/lib/php/db/table.php index d3b848ba..3bbb5996 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -710,15 +710,19 @@ Class Table extends nb { } + private function splitLimit($limit) { + return strpos($limit,',')!==false + ? preg_split('/\s*,\s*/',$limit) + : [0,$limit] + ; + } + public function nav($count,$tot,$limit) { $html = ''; if ($count<$tot) { - list($x,$y) = strpos($limit,',')!==false - ? preg_split('/\s*,\s*/',$limit) - : [0,$limit] - ; + list($x,$y) = $this->splitLimit($limit); $prev = $x - $y; $next = $x + $y; @@ -734,7 +738,7 @@ Class Table extends nb { if ($prev>=0) $html .= '<< '; - $html .= ''.($tot ? ($x+1) : 0).' - '.( $count<($x+$y) ? $count : ($x+$y) ).' / '.$tot.''; + $html .= ''.($tot ? ($x+1) : 0).' - '.( $tot<($x+$y) ? $tot : ($x+$y) ).' / '.$tot.''; if ($next<$tot) $html .= ' >>'; @@ -993,10 +997,8 @@ Class Table extends nb { if ($this->p('orderby') and !$count) $sql .= ' ORDER BY '.$this->p('orderby'); - if ($_limit = $limit = $this->db()->limit) { - $_limit = str_replace(' OFFSET ',',',$_limit); - $_limit = str_replace(',',' OFFSET ',$_limit); - $sql .= ' LIMIT '.$_limit; + if ($limit = $this->db()->limit) { + $sql .= ' LIMIT ' . join(' OFFSET ',array_reverse($this->splitLimit($limit))); } else { $limit = ''; } @@ -1433,9 +1435,7 @@ Class Table extends nb { 'total_pages' => ceil($this->tot / $limit) // calculate pages count ]); - #$this->_html_table->display_tablenav('top'); $this->_html_table->display(); - #$this->_html_table->display_tablenav('bottom'); unset($this->_html_table); return ''; } -- 2.47.3