PEAR::DB question
| From: | Jacob Marble | Date: | Mon, 28 Jul 2003 21:33:53 +0000 |
| Subject: | PEAR::DB question | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-29546@lists.php.net to get a copy of this message | ||
Hello-
I'm using the fetch method to get a result set. ie-
$sql = "select id,name from sr_names order by name";
$result = $db->query($sql);
while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) )
echo $row['id'] . ' ' . $row['name'] . "<br>";
This works great! Now, I want to _re-use_ this result set without
having to re-query the database. Then cycle through the result set. ie -
$result->someFunction();
while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) )
echo $row['id'] . ' ' . $row['name'] . "<br>";
So, the output here would be two of whatever was output. Does that make
sense? Right now I'm having to do this:
$sql = "select id,name from sr_names order by name";
$result = $db->query($sql);
while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) )
echo $row['id'] . ' ' . $row['name'] . "<br>";
$result = $db->query($sql);
while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) )
echo $row['id'] . ' ' . $row['name'] . "<br>";
If I already have the result set, can't I just tell it "hey, put the
cursor back at the top". I know I can fetchRow from a specific row in the
result set, but then I'd have to get every row that way, which doesn't make
efficiency sense, either.
Thanks in advance,
Jake
LandEZ