DB_result::getPagerData()
| From: | Tomas V.V.Cox | Date: | Mon, 02 Apr 2001 00:31:55 +0000 |
| Subject: | DB_result::getPagerData() | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-143@lists.php.net to get a copy of this message | ||
Hello again,
I've coded a new feature for DB.php, this is the ability to calculate
all the data needed to represent paginated lists from a query result
set. This is very usefull and needed in web programing for building the
tipical Next/Prev buttons (of course this can do more than this, see
inline doc).
Here is an example of use:
<?php
$dsn = 'pgsql://postgres@localhost/mydb';
if (DB::isError($con = DB::connect($dsn))){
die ();
}
$sql = "select * from clients";
if (DB::isError($res = $con->query($sql))){
die ();
}
$from = 510;
$limit = 10;
$p = $res->getPagerData($from, $limit);
// View the data
print_r($p);
foreach (range($p['from'], $p['to']) as $rownum){
if (!$row = $res->fetchrow(DB_MODE_DEFAULT, $rownum)){
break;
}
print_r($row);
}
?>
For the moment it should work only with mysql, ifx and pgsql (they have
the extra $rownum param in fetchrow/fetchinto). Others is work in
progress. It needs numrows(), but if your backend doesn't support it,
you can calculate it for your self and pass it to getPagerData (third
param).
Before comit the patch I need from you to approve this. It can be easily
transform in a separate class if you don't think that this should go in
the core of DB.
Tomas V.V.Cox