Efficient loop through PEAR's $db->getAll($sql)
Posted: Mon Sep 08, 2003 12:34 pm
Okay, so I'm finally using PEAR's DB classes, and they are great, but I'm not sure the best way to loop through this info.
Using this:
is a great alternative to
except, that the $db class dumps the info into a two-dimensional (or is it two layered?) array, which makes it hard to pull it out and loop through it.
So far, this is the best I've come up with:
There's got to be an easier way to pull info from get*() rather than just looping through the returned array twice. If not, I'll go back to my old while loop. Any suggestions?
Too bad the PEAR docs don't let you add notes. :T
PEAR Doc: http://pear.php.net/manual/en/package.d ... -fetch.php
Steve
Using this:
Code: Select all
$array=$db->getAll($sql)Code: Select all
$sql="SELECT blah";
$rs=mysql_query($sql);
$array=mysql_fetch_array($rs);So far, this is the best I've come up with:
Code: Select all
// Set arrays from the first array:
for($i=0; $i<count($array); $i++) {
$array_contentї$i]=$arrayї$i];
}
// And then do it a second time, for the info in that array:
for($j=0; $j<count($array_content); $j++) {
echo $array_contentї$j]ї'id'];
}Too bad the PEAR docs don't let you add notes. :T
PEAR Doc: http://pear.php.net/manual/en/package.d ... -fetch.php
Steve