有人可以顯示,固定或告訴我爲什麼我收到此錯誤調用一個成員函數在非對象 - PHP
Call to a member function getRating() on a non-object
下面是函數
public function getRating($movieid){
$movieid = mysql_real_escape_string($movieid);
$average = 0;
$e = mysql_query("SELECT AVG(`rating`) as average FROM movie_ratings WHERE movieid='$movieid'") or die(mysql_error());
if (mysql_num_rows($e)>0){
extract(mysql_fetch_array($e));
}
return $average;
}
而且這就是我所說的功能
$movie = $movie->getByPerma($perma,$language);
if (empty($movie)){
$movie = '';
} else {
$movie['rating'] = $movie->getRating($movie['id']);
$tags = $movie->getMovieCategoryDetails($movie['id'],$language);
if (count($tags)){
$smarty->assign("tags",$tags);
} else {
$smarty->assign("tags","");
}
}
有人可以幫助我,因爲我是新來的PHP。
是什麼'getByPerma'嗎? –
你正在用一個名爲'$ movie'的數組覆蓋你的'$ movie'對象,所以當你嘗試可以調用'getRating()'時,你就在該數組上調用它,因此錯誤'在非對象」。所以只需將數組分配給不同的變量。 – Graham
@格拉漢姆:評論應該是答案... – Thalaivar