PEAR Access Kills While Loop

From: Date: Thu, 21 Sep 2006 15:42:13 +0000
Subject: PEAR Access Kills While Loop
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-25189@lists.php.net to get a copy of this message
I have a loop that prints out the data from a query into table rows, as shown below. [PHP] $res =& $db->query("SQL Query Here"); $printed = 0; while($res->fetchInto($row)){ if($printed%2!=0){$rowcolor="#EEEEEE";}else{$rowcolor="#FFFFFF";} $filmType = $films->convertType($row->film_type); $dateAdded = $films->convertDateAdded($row->dateadded); //$filmStatus = $films->printStatus($row->filmID); print<<<eof <tr bgcolor=$rowcolor> <td class="small">$row->filmID</td> <td class="small">$dateAdded</td> <td class="small">$filmType</td> <td><a href="$PHP_SELF?action=view&filmID=$row->filmID">$row->title</a></td> <td>$filmStatus</td> <td class="small"><a href="/profile_$row->userID.html">$row->firstname $row->lastname</a></td> <td><img src="images/edit.gif" alt="edit" width="14" height="15" border="0"></td> </tr> eof; $printed++; } [/PHP] Notice the line that is commented which includes the variable $filmStatus. When that line is NOT commented, the loop only prints the first result from the query. When it IS commented, the loop prints all the results as it should. $films->printStatus() is this function in the class: [PHP] function printStatus($filmID){ $status = $this->db->getOne("SELECT active FROM films WHERE filmID = '$filmID'"); if($status->active == 1){ $printStatus .= "<img src=\"images/active.gif\" width=\"12\" height=\"11\">&nbsp;"; } else { $printStatus .= "<img src=\"images/inactive.gif\" width=\"12\" height=\"11\">&nbsp;"; } return $printStatus; } [/PHP] And yes, I know it seems like overkill to just check one little status column but the function will eventually check many more columns and conditions and print out more images and text based on the results. So, when that function is called, the loop in which it is contained stops after the first run. Any ideas? /alex

« previous php.pear.general (#25189) next »