Reply to Re: creating a cumulative total column, but not in sequence

Your name:

Reply:


Posted by mantrid on 12/29/07 13:23

"Ivαn Sαnchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
wrote in message news:fl3rop$dge$1@hercules.cohp1...
> mantrid wrote:
>
> > I looked at the manual. and it does look like its due to my version of
> > php. Seems using & to modify array's elements is only available in
version
> > 5. What should I do?
>
> First, upgrade to PHP5 ;-)
>
> (Remember that PHP4's end-of-life is near, BTW)
>
> Second, modify the array elements by using the array name and the relevant
> key:
>
> Instead of
>
> foreach ($array as $key=>&$item)
> {
> $item['foo'] = $whatever;
> }
>
> use something like:
>
> foreach ($array as $key=>$item)
> {
> $array['key']['foo'] = $whatever;
> }
>

Ok Ive been tinkering with your solution and my ignorance of arrays has
stumped me again. It looks like I should be recreating the array along the
lines of (pseudo code)
array (oldelement1,oldelement2)= newarray (newelement1,newelement2)
If element1 is the key this will remain the same and element2 is the
cumulative total will change. So I tried

$data['key']['accum'] = $key =>$accum += $item['profnloss'];
initially, but it didnt work

I ended up with

foreach($data as $key=>$item)
{
if ($item['profnloss'] > 0)
$data['key']['accum'] = $accum += $item['profnloss'];
else
$data['key']['accum'] = $accum;
}

This sort of worked a bit in that in the displayed results the first line
had no values exept the overall cumulative total. ie
Held Order- Sell Date- Profit/Loss- Cumulative Total-1005.06506667


and all the other rows had all the other data exept the cumulated total. ie
Held Order-371 Sell Date-2007-05-03 16:14:00 Profit/Loss--39.98 Cumulative
Total-
Held Order-688 Sell Date-2007-06-01 12:42:00 Profit/Loss-158.5254068123
Cumulative Total-
Held Order-377 Sell Date-2007-06-11 16:21:00 Profit/Loss-80.9849999999997
Cumulative Total-
Held Order-750 Sell Date-2007-08-02 12:07:00 Profit/Loss-548.267993187701
Cumulative Total-

Again excuse my ignorance. What have I got wrong
Ian

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация