Forum Moderators: coopster
//lickuid//
select avg(Price) from wherever where whatever
or select avg(Price) as a from wherever where whatever
the second will return a variable called 'a' with the value in it so you can go do something with it if you wish.
Mysql is much faster than doing any kind of calculations in the result set with php.
<?php
//must already be connected to MySQL
$r = mysql_query("SELECT * FROM table");
$num = mysql_num_rows($r);
while($data = mysql_fetch_array($r)) {
$total = $data['column'] + $total;
}
$avg = $total / $num;
echo $avg;
?>