i am not sure if i am doing this correctly, and i am kinda stucked here.
Here's what i want to do, each row in the database has 5 column, say A,B,C,D with each having an integer value out of 10 and E which is like a counter. so what i want is to get an average.
which should be something like below
(A + B + C + D)/(E * 4)
and each of these values calculated above, has to be summed up and divide by the total number of rows.
So say i have 3 entry it has to divided by 3
so what i came up with is
$myresult = mysql_query("SELECT * FROM studies WHERE classes = '$classid'");
list($mycount) = mysql_fetch_row($myresult);
$result = mysql_query("SELECT ID, sum((maths + sciences + moral + bm)/(count*4))/'$mycount' FROM studies WHERE classes = '$classid'");
am i doing this right?
if the sql is right, how am i suppose to print out the result so i can use it as a variable?
thank you
SELECT id, sum((maths + .........)) as 'avg' ...so you will haveavgrow keys in your fetched array