Ok, 2 ways minimum to do it.
1 - Static way (your way):
$totalaverage = mysql_query("SELECT avg(totalrating) FROM table");
$anotherrow = mysql_result($totalaverage,0);
echo $anotherrow;
2 - Dynamic way:
$column = "totalrating";
$totalaverage = mysql_query("SELECT avg($column) FROM table");
$anotherrow[$column] = mysql_result($totalaverage,0);
echo $anotherrow[$column];
---- OR if you like -----
echo $anotherrow['totalrating'];
Hope it helps.