SELECT AVG(Overall) FROM Table WHERE User_id=74
Thanks you for your replies. The average in the sql query works great. On the next step of this project I am trying to get this to work in a combine query. For instance, in this situation I would also like to display some information about the user along with their average score. The information about the user is contained in the users table.
As of now I am having difficulty getting the avg() to work in a combine query. The error result is as follows:
Warning: Supplied argument is not a valid MySQL result resource on line 15
Warning: Supplied argument is not a valid MySQL result resource on line 16
The query I am using is as follows:
$query = "SELECT users.User_name, AVG(scores.overall)
from users, scores
where users.User_id = 74 and scores.User_id = 74";
$result = mysql_query($query);
$num = mysql_numrows($result);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p>".($i+1).".";
echo "_______________________________________";
echo "<br> User Name: ";
echo "<b>";
echo htmlspecialchars( stripslashes($row["user_name"]));
echo "</b>";
echo "<br>";
echo "<br> Average Score: ";
echo "<b>";
echo htmlspecialchars( stripslashes($row["overall"]));
echo "</b>";
echo "<br>";
}
My question does "avg()" work in combine queries or do I have to change technique to accomplish this? I am thinking that there is simply something wrong with my query.
In the end, what the fuction will be is to display a list of users sorted by thier average score ranking from highest first to lowest last. So you would come out with something like the following:
Name: Joe Blow
Average Score: 100
Name: Jim Blow
Average Score: 98
Name Jill Blow
Average Score: 74
Thank you in advance,