DBI

Brendon Oliver brendon.oliver at redsheriff.com
Thu Apr 1 23:42:31 CST 2004


On Fri, 2 Apr 2004 03:00 pm, Alfie John wrote:
> How would I scroll a DBI resultset? I would like to page a resultset
> just like every other website, but I am stumped how to do it
> db-independently. I know how I would go about paging for "previous
> results" or "next results" page, but I wouldn't have a clue to so
> something like "go to results 40-50".

I'm not familiar with other DBs but from experience using postgresql this is 
relatively easy.  Just use the LIMIT and OFFSET clauses of the SELECT 
statement.  LIMIT translates to your number of records per page, OFFSET tells 
it where to start retrieving records.

Eg.  SELECT * from my_table LIMIT 10 OFFSET 40

will give you your "go to results 40-50" request (more correctly, records 40 
thru 49 inclusive).   You just need to cache the limit / offset somewhere for 
possib;e re-use between page requests.

 Also, the DBD::Pg driver supports the rows() method properly, which will give 
you the count of records retrieved by your SELECT statement which you might 
find useful to have too.

HTH.

Regards,

- Brendon.
-- 
Ever get the feeling that the world's on tape and one of the reels is missing?
		-- Rich Little

 15:36:02 up 31 days,  3:28,  5 users,  load average: 0.18, 0.20, 0.13





More information about the Melbourne-pm mailing list