本文介紹了警告問題:期望參數 1 為 mysqli_result的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我收到下面列出的警告,我想知道如何修復它
I get the following warning listed below and I was wondering how do I fix it
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given on line 65
代碼圍繞下面列出的 PHP 代碼部分.如果需要,我可以列出完整的代碼.
The code is around this section of PHP code listed below. I can list the full code if needed.
// function to retrieve average and votes
function getRatingText(){
$dbc = mysqli_connect ("localhost", "root", "", "sitename");
$sql1 = "SELECT COUNT(*)
FROM articles_grades
WHERE users_articles_id = '$page'";
$result = mysqli_query($dbc,$sql1);
$total_ratings = mysqli_fetch_array($result);
$sql2 = "SELECT COUNT(*)
FROM grades
JOIN grades ON grades.id = articles_grades.grade_id
WHERE articles_grades.users_articles_id = '$page'";
$result = mysqli_query($dbc,$sql2);
$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)';
}
}
推薦答案
mysqli_query()
如果查詢中有錯誤,則返回 FALSE
.所以你應該測試一下...
mysqli_query()
returns FALSE
if there was an error in the query. So you should test for it...
/* Select queries return a resultset */
if ($result = mysqli_query($dbc, "SELECT Name FROM City LIMIT 10")) {
printf("Select returned %d rows.
", $result->num_rows);
/* free result set */
$result->close();
}
請參閱此鏈接以獲取 mysqli_query
參考http://php.net/manual/en/mysqli.query.php
See this link for the mysqli_query
reference
http://php.net/manual/en/mysqli.query.php
這篇關于警告問題:期望參數 1 為 mysqli_result的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!