PHP-致命错误:不支持的操作数类型 [英] PHP - Fatal error: Unsupported operand types
本文介绍了PHP-致命错误:不支持的操作数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直收到以下错误,我想知道如何解决?
I keep getting the following error and I was wondering on how to fix?
这是我第二次遇到此错误,我是第一次修复此错误,但由于某种原因我无法第二次修复它.
This is the second time I got this error I fixed it the first time but for some reason I cant fix it the second time.
Fatal error: Unsupported operand types on line 103
这是第103行.
$avg = (round($total_rating_points / $total_ratings,1));
这是下面的完整代码.
function getRatingText(){
$dbc = mysqli_connect ("localhost", "root", "", "sitename");
$page = '3';
$sql1 = "SELECT COUNT(users_articles_id)
FROM articles_grades
WHERE users_articles_id = '$page'";
$result = mysqli_query($dbc,$sql1);
if (!mysqli_query($dbc, $sql1)) {
print mysqli_error($dbc);
return;
}
$total_ratings = mysqli_fetch_array($result);
$sql2 = "SELECT grade_points
FROM grades
JOIN articles_grades ON grades.id = articles_grades.grade_id
WHERE articles_grades.users_articles_id = '$page'";
$result = mysqli_query($dbc, $sql2);
if (!mysqli_query($dbc, $sql2)) {
print mysqli_error($dbc);
return;
}
while($row = mysqli_fetch_array($result)) {
$trp[] = $row[0];
}
$total_rating_points = array_sum($trp);
if (!empty($total_rating_points) && !empty($total_ratings)){
$avg = (round($total_rating_points / $total_ratings,1));
$votes = $total_ratings;
echo $avg . "/10 (" . $votes . " votes cast)";
} else {
echo '(no votes cast)';
}
}
推荐答案
$total_ratings
是一个数组,不能用于除法.
$total_ratings
is an array, which you can't use for a division.
从上方:
$total_ratings = mysqli_fetch_array($result);
这篇关于PHP-致命错误:不支持的操作数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文