For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > September 2007 > Re: [PEAR] Iterating through resultset more than once?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] Iterating through resultset more than once?
Adam Harvey

2007-09-12, 8:02 am

Quoting john mclaughlin <jackstrummer@yahoo.co.uk>:
> wondered if you could help with this:
> Using DB package I get a resultset from a query and iterate thru it.
> Only problem is, how do I reset the resultset to point to its first
> index so I can iterate thru
> again.
> The DB.result class doesn't seem to have any relevant methods.
> Weird. At present I am having to needlessly rerun the query and get
> a fresh resultset which is incredibly wasteful, obviously.


Manually setting the row number in call to the fetchRow() method
should reset the internal counter. For example:

$row = $result->fetchRow(DB_FETCHMODE_DEFAULT, 0);

That should return the first row, and subsequent calls to fetchRow()
should return the second, third, fourth, etc rows.

Adam

--
Adam Harvey PEAR Profile: <http://pear.php.net/user/aharvey>
Blog: <http://xn--9bi.net/>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com