
March 30th, 2000, 01:21 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
Why are you setting old twice?
if new is the name of the form field that will be the name of the variable. The other problem is that you don't know how many values have previously been averaged in to old, so you don't have a correct divisor. The easiest way I see to do this is initialize the row with 0 for old and a field 'cnt' with a value of 0. Then you can do this:
update table set old=old+$new, cnt=cnt+1 where id=$id
Then to get the average at any point
select old/cnt as avg from table where id=$id
Notice that old does not have a $ in front of it as you are using the value of old from the table. Also, you can't use avg() the way you are trying as that function is to get the average of a column across several records and needs the group by clause set to know which records to include.
|