mysqli_result类的对象无法转换为返回mysql平均值的字符串


Object of class mysqli_result could not be converted to string return mysql average

有人能解释一下我将如何输出下面的sql结果吗?当前正在获取"无法将mysqli_result类的对象转换为字符串"。

$sql = ("SELECT AVG(ab_satisfactionScore) AS AverageSatisfactionScore
     FROM tbl_appointmentsbooked;");
$result = mysqli_query($connection, $sql);
echo ($result);

错误,因为您正在回显一个对象,所以尝试这样做,

while($res = mysqli_fetch_array( $result )) {
    echo $res['AverageSatisfactionScore'];
} 

使用任何mysqli_fetch_*()函数(或OOP样式中的$result->fetch_*())从mysqli_results对象($results)中检索结果。

有关各种方法及其用法,请参阅mysqli_result文档。

因为您试图使用echo打印对象,而它过去只打印字符串,所以您应该使用:

print_f($result);

而不是

echo ($result);