RE: [PEAR-DEV] DB_Pager
| From: | LIMBOURG Arnaud | Date: | Wed, 10 Jul 2002 07:20:57 +0000 |
| Subject: | RE: [PEAR-DEV] DB_Pager | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-7610@lists.php.net to get a copy of this message | ||
YOu're right, if you use limitQuery you're stuck.
Tou have to do one limit query then a simple query just to get numRows().
So, it's not such a good idea to use limitQuery() ;))))
But tomas already knows, right ? ;)
Arnaud.
> Hi
>
> I don't get it...
>
> In the latest version of db_pager there is a small sample, but....
>
> If you use the limitQuery, then you only get xx records and
> then the call to
> DB_Pager::getData() don't contain any usefull information.
> Small sample:
> <?php
> require_once 'DB/Pager.php';
> $db = DB::connect("mysql" . "://" . "test" .":" .
> "test" . "@" .
> "localhost" . "/" . "test");
> $from = (isset($_GET['from']) ? $_GET['from'] : 0);
> $limit = 10;
> $maxpages = 10;
> $sql = "select * from test";
> $res = $db->limitQuery($sql, $from, $limit);
> $nrows = $res->numRows();
> while ($row = $res->fetchrow(DB_FETCHMODE_ASSOC))
> {
> echo $row['id'] . " " . $row['text'] .
> "<br>";
> }
>
> $data = DB_Pager::getData($from, $limit, $nrows, $maxpages);
> print "<pre>";
> print_r($data);
> print "</pre>";
> ?>
>
> and the print_r output:
> Array
> (
> [numpages] => 1
> [firstpage] => 1
> [lastpage] => 1
> [pages] => Array
> (
> [1] => 0
> )
>
> [current] => 1
> [maxpages] => 10
> [prev] =>
> [next] =>
> [remain] => 0
> [to] => 10
> [numrows] => 10
> [from] => 1
> [limit] => 10
> )
>
> As you can see, the prev and nex is empty. There is more than
> 10 records in
> the table ;-)
> So the limitQuery() might not be a good choice, or am i
> missing the point ?
> Best
> Steen
>
>
>
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>