Jump to content

[SOLVED] php does not print out the right average!!!! how come?


uisneach

Recommended Posts

Hello mates;)

 

here a problem.

I have this

 

$sql15 = "UPDATE train_delay SET delay = (delay+'$delay')/numdelays WHERE day= '$day' AND month = '$month' AND year = '$year' AND hour = '$hour' AND direction = '$direction' ";

$result = mysql_query ($sql15);

 

Train delay is a table on mysql having all the fields correctly set

num delay is incremented by this

 

$cont = 1

$sql13 ="UPDATE train_delay  SET numdelays  = (numdelays +'$cont')  WHERE day= '$day' AND month = '$month' AND year = '$year' AND hour = '$hour' AND direction = '$direction' ";

$result2 = mysql_query ($sql13);

 

 

The strange thing is that when I insert three times the value 10 as delay, the delay average reckoning works but only until the second entry.

e.g.

1 delay 10 average of course is 10

2 delay 10 (again) average is 10

3 dealy 10 average is 7!!!!!! I don't understand nothing

 

The proof that the "settings" are cool is that if I put this

delay = (delay+'$delay')

without  divided by numdelays (the counter)

is correct!!! and equal 30!

 

the same, as well, for numdelays "alone".

It indicates 3 entries...so the number is correct!!!!

SO HOW THE **** THIS ******* AVERAGE DOES NOT WORK??? ???

 

anyoine has some clue/suggestion/idea/advice?

 

Thx in advance for your precious help

bye

paul

:)

store 2 columns "total_delay" and delay_count

 

UPDATE train_delays SET
    total_delay = total_delay + $delay,
    delay_count = delay_count+1
WHERE ...

 

then the average is always total_delay/delay_count

 

EDIT: You are adding the delay to the previous average, not the previous total

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.