This is a discussion on PEAR::DB_Pager: a very strange USAGE!!!! within the PHP Language forums, part of the PHP Programming Forums category; HI, this is the usage code suggested by the author of PEAR::DB_Pager. <?php require_once 'DB/Pager.php'; $db = ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
HI,
this is the usage code suggested by the author of PEAR::DB_Pager. <?php require_once 'DB/Pager.php'; $db = DB::connect('mysql://root@:localhost/global'); $from = 0; // The row to start to fetch from (you might want to get this param from the $_GET array $limit = 3; // The number of results per page $maxpages = 10; // The number of pages for displaying in the pager (optional) $sql = "select * from item"; $res = $db->limitQuery($sql, $from, $limit); $nrows = 0; // Alternative you could use $res->numRows() while ($row = $res->fetchrow()) { // XXX code for building the page here $nrows++; } $data = DB_Pager::getData($from, $limit, $nrows, $maxpages); echo $nrows . '<br>'; // XXX code for building the pager here ?> I found it strange, because this code always shows one page, beacuse of the $nrows param in the getData call. If I change the line $data = DB_Pager::getData($from, $limit, $nrows, $maxpages); into $data = DB_Pager::getData($from, $limit, 12, $maxpages); It works correctly (12 is the number of rows in the item table), it gives me the right statistics for the next and previous pages, etc.... Maybe there is something I don't' understand, but with the suggested usage, the pager is useless!! Thanks for any hint. :)ario |