Forum Moderators: coopster

Message Too Old, No Replies

Treating certain numbers as null

Adding missing values together

         

s9901470

11:55 am on Jan 23, 2006 (gmt 0)

10+ Year Member



Hi

I want to retrieve a line of numbers from a table, ranging from 1 to 5. I've stored missing values as 8.

I want to add them together using PHP, but treat 8 as missing/null, not as the number 8. Any suggestions?

e.g. 1 + 5 + 8 = 6

Thank you in advance.

Ed

larryhatch

12:05 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried storing missing numbers as zero?

If that doesn't apply, have an intermediate variable V.
Lets say your values are stored in an array val[], and there are 'max' of them stored.
Let i be a simple index counter.

for (i=0; i=max; i++)

{ V = val[i];
if V==8 V=0;
SUM = SUM+V;
}

I might have assignment and equality operators mixed up, but hopefully you get the idea. -Larry

s9901470

1:14 pm on Jan 23, 2006 (gmt 0)

10+ Year Member



Great, many thanks.

Slightly more complicated: What if I want to exclude a whole line if I think that there are too many null values?

For example, someone has entered 1,3,2,5 and then there are several missing values.

I think that more than four '8's (missing) should void the whole line.

Is that possible to specify with PHP?