PDA

View Full Version : Averages with PHP



Romanity
05-05-2008, 12:53 PM
Right... heres what I got so far



$mean = array( 2, 4, 6, 8 );
$mean = array_sum($mean);
$mean = $mean/4;
echo "$mean";


Which does give 5 as the answer :)
Problem is i cant remember how to get the array from the database :S



$mean = array( ALL DATABASE VALUES);


Is what I need.... whats the function??? :S

MrCraig
05-05-2008, 03:10 PM
$sql = mysql_query("select * from YOURDATABASETABLENAME");
$mean = mysql_fetch_array($sql);

Romanity
05-05-2008, 04:21 PM
Swear i tried that
O well my bad (A)
Cheers :)

Baving
05-05-2008, 07:01 PM
MySQL has a built in average function avg() you may use.

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_avg

Jackboy
06-05-2008, 08:35 AM
MySQL has a built in average function avg() you may use.

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_avg

Php pro ^

I never knew about that site/function, cheers

Romanity
06-05-2008, 06:03 PM
Cheers Alan :)

Want to hide these adverts? Register an account for free!