RE: [PHP-DB] Averaging Numbers

From: Date: Wed, 15 Aug 2001 16:58:56 +0000
Subject: RE: [PHP-DB] Averaging Numbers
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-11386@lists.php.net to get a copy of this message
That's exactly what I needed. Thanks. I'm absolutely awful with math and this is my first time averaging numbers from a database. Jeff Oien > Maybe I am missing the complexity but I would just add them all up as > you retrieve them (or where you are printing them out) and then when you > finish the loop divide the total by the number of of number you are > averaging over have (i.e this would be 15 if you are taking 15 days). > > something like: > > $sum = 0; > for i=0 to i=15 > { > $valueRetrieved = retrieve result of row i > $sum += $valueRetrieved > } > $average = $sum/15 > > hope this helps > andre > > Jeff Oien wrote: > > >I'm having a hard time learning how to get an average. I have a database > >that gets a number and inserts in into a MySQL database every 1/2 hour > >during the day. For the current half hour, I want to get the last 15 days > >numbers for the same time as the time it is now. I can retrieve and display > >the numbers fine, I just don't know how to go about putting these all into > >variables or an array or if I can do this within a query and then take an > >average for them. Hope that made sense. Thanks. > >Jeff Oien > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#11386) next »