
Originally Posted by
Roger Ramjet
QUERIES INSIDE LOOPS ARE WRONG - ALWAYS AND EVERY TIME.
I've read quite a few different people say this, so i was wondering if the following qualifies as a query inside a loop.
Say i have a class, clsPictureFinder, that has a static method called GetAllPics which returns an array containing all the picture database ID's on a certain table. I defer the object creation of an individual Picture object until i'm actually looping through them, by passing the pictureID to the constructor, which is in turn triggering another query, to populate the objects properties- a query inside a loop? eg:
PHP Code:
$arrPicIDs = array();
$arrPicIDs = clsPictureFinder::GetAllPics();
foreach($arrPicIDs as $key=>$value)
{
$objPicture = &new clsPicture($value);
echo $objPicture->getFilename() . '<br />';
echo $objPicture->getOwner() . '<br />';
echo $objPicture->showThumbnail();
echo '<hr />';
unset($objPicture);
}
Is this bad practice?
Bookmarks