uisneach Posted October 14, 2008 Share Posted October 14, 2008 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 Link to comment https://forums.phpfreaks.com/topic/128431-solved-php-does-not-print-out-the-right-average-how-come/ Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 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 Link to comment https://forums.phpfreaks.com/topic/128431-solved-php-does-not-print-out-the-right-average-how-come/#findComment-665563 Share on other sites More sharing options...
uisneach Posted October 15, 2008 Author Share Posted October 15, 2008 Hello barand really thx you now it's solved i made a big mistake, fool me it's true what you said. now i made the right way with your advice cheers :) the problem is really solved. bye Link to comment https://forums.phpfreaks.com/topic/128431-solved-php-does-not-print-out-the-right-average-how-come/#findComment-666016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.