Pager bug

From: Date: Mon, 02 Jun 2003 08:20:52 +0000
Subject: Pager bug
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16886@lists.php.net to get a copy of this message
Hi again In the search for a PEAR pagination class, I'm now using Richard's Pager class :-) Aside from a v. small bug this one works as expected. The bug is as follows: (float)total num rows / (float)results per page = result -> result after rounding 138 / 10 = 13.8 -> 14 141 / 10 = 14.1 -> 14 259 / 20 = 12.95 -> 13 the class appears to incorrectly round up the result where it should be rounded down. Eg: if you have 138 rows, with 10 res/page, you'll need 13 pages to display them, not 14. The following diff fixes the problem: ? Pager.diff Index: Pager.php =================================================================== RCS file: /repository/pear/Pager/Pager.php,v retrieving revision 1.9 diff -u -r1.9 Pager.php
--- Pager.php   4 Jan 2003 11:56:13 -0000       1.9
+++ Pager.php 2 Jun 2003 08:07:47 -0000 @@ -289,7 +289,7 @@
         if ($this->_itemData !== null) {
             $this->_totalItems = count($this->_itemData);
         }
-        $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
+        $this->_totalPages = floor((float)$this->_totalItems / (float)$this->_perPage);
         $i = 1;
         if (!empty($this->_itemData)) {
             foreach ($this->_itemData as $key => $value) {
@@ -405,4 +405,4 @@
     }
} -?> \ No newline at end of file +?> Who is maintaining Pager now ? cheers Demian

« previous php.pear.dev (#16886) next »