How to use avg function?

Posted by Marcelo on Stack Overflow See other posts from Stack Overflow or by Marcelo
Published on 2010-06-09T23:34:07Z Indexed on 2010/06/09 23:42 UTC
Read the original article Hit count: 236

Filed under:
|
|
|

I'm new at php and mysql stuff and i'm trying to use an avg function but i don't know how to.

I'm trying to do something like this:

mysql_connect(localhost,$username,$password);

@mysql_select_db($database) or die ("Did not connect to $database");

mysql_query("AVG(column1) FROM table1 ") or die(mysql_error());

mysql_close();

echo AVG(column1);

(Q1)I'd like to see the value printed in the screen, but i'm getting nothing but an error message. How could I print this average on the screen ?

(Q2)If I had a column month in my table1, how could I print the averages by the months ?

Sorry for any bad English, and thanks for the attention.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql