$result = mysql_query("SELECT AVG(fieldName) AS avg FROM tableName");
$row = mysql_fetch_assoc($result); echo $row['avg']
//1 selecting the average from table column
$sql = "SELECT avg(columnName) as whatever FROM tableName";
//2 getting the result
$result = mysqli_query($conn, $sql);
//3 fetch as array
$numratingsa = mysqli_fetch_all($result, MYSQLI_ASSOC);
//4 select last element of array which is average
$myLastElementa = end($numratingsa);
//5 converts array to string
$stringo = implode($myLastElementa);
// *optional* round value to one decimal place
$roundin = round($stringo, 1);
//6 show output
echo $stringo;
echo $roundin;