Tôi tiếp tục nhận được lỗi sau và tôi đã tự hỏi cách khắc phục.Lỗi nghiêm trọng: Các loại toán hạng không được hỗ trợ
Fatal error: Unsupported operand types on line 97
Khu vực xung quanh mã này được liệt kê bên dưới. Tôi có thể liệt kê toàn bộ mã nếu cần.
mã PHP
$total_rating_points = mysqli_fetch_array($result);
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)';
}
Đây là dòng 97
$avg = (round($total_rating_points/$total_ratings,1));
Dưới đây là toàn bộ mã.
function getRatingText(){
$dbc = mysqli_connect ("localhost", "root", "", "sitename");
$page = '3';
$sql1 = "SELECT COUNT(*)
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 COUNT(*)
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;
}
$total_rating_points = mysqli_fetch_array($result);
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)';
}
}
cách khắc phục điều này vì tôi cần chia $ total_rating_points/$ total_ratings – tEcHnUt
$ total_ratings [0]/$ total_rating_points [0]. Bạn cũng có thể kiểm tra xem Count (*) có phải là hàm tổng hợp chính xác cho cả hai truy vấn không. – VolkerK