note 64124 added to function.fclose

From: Date: Sat, 08 Apr 2006 01:19:37 +0000
Subject: note 64124 added to function.fclose
Groups: php.notes 
Request: Send a blank email to php-notes+get-107548@lists.php.net to get a copy of this message
Trying to understand how 'end foreach' and 'endwhile' differ, I've encountered a problem I can't solve by myself. The following is a fairly easy stock portfolio script. Everything works, except at the end where I want to calculate the average of the gains as represented by $gain[$i]. <?php $quantity="3"; $stocks=array("iso","grn","bdgr.pk"); $buydates=array("3 jan 2006","1 feb 2006","3 apr 2006"); $prices=array("0.32","0.20","0.95"); $recommends=array("hold","strong buy","buy"); $i=0; echo"<tr>"; echo "\n<th align='center'>ticker</th>"; echo "\n<th align='center'>buy date</th>"; echo "\n<th align='center'>price $</th>"; echo "\n<th align='center'>recommend</th>"; echo "\n<th align='center'>value $</th>"; echo "\n<th align='center'>change %</th>\n</tr>\n"; foreach($stocks as $stock) { $fp=fopen("http://","r"); $data=fgetcsv($fp,1000,","); $values=$data[1]; echo "<tr>\n<td align='center'>".$stock."</td>"; echo "\n<td align='center'>".$buydates[$i]."</td>"; echo "\n<td align='center'>".$prices[$i]."</td>"; echo "\n<td align='center'>".$recommends[$i]."</td>"; echo "\n<td align='center'>".$values."</td>\n<td align='center'>"; echo $gain[$i]=round(((($values-$prices[$i])/$prices[$i])*100),2); echo "</td>\n</tr>"; fclose ($fp); $i++; } echo "\n<tr>\n<td align='center'>".$gain[$i]."<td>\n</tr>\n"; ?> Help? ---- Server IP: 64.71.164.2 Probable Submitter: 66.177.130.77 ---- X-Spam-Status: Yes, hits=6.9 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_30_40,HTML_MESSAGE,STRONG_BUY autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.fclose.php Edit -- http://master.php.net/note/edit/64124 Del: integrated -- http://master.php.net/note/delete/64124/integrated Del: useless -- http://master.php.net/note/delete/64124/useless Del: bad code -- http://master.php.net/note/delete/64124/bad+code Del: spam -- http://master.php.net/note/delete/64124/spam Del: non-english -- http://master.php.net/note/delete/64124/non-english Del: in docs -- http://master.php.net/note/delete/64124/in+docs Del: other reasons-- http://master.php.net/note/delete/64124 Reject -- http://master.php.net/note/reject/64124 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107548) next »