我試圖執行一些查詢以獲取有關某些圖像的信息頁面。我寫了一個功能致命錯誤:調用非對象的成員函數fetch_assoc()
function get_recent_highs($view_deleted_images=false)
{
$lower = $this->database->conn->real_escape_string($this->page_size * ($this->page_number - 1));
$query = "SELECT image_id, date_uploaded FROM `images` ORDER BY ((SELECT SUM(image_id=`images`.image_id) FROM `image_votes` AS score)/(SELECT DATEDIFF(NOW() , date_uploaded) AS diff)) DESC LIMIT " . $this->page_size . " OFFSET $lower"; //move to database class
$result = $this->database->query($query);
$page = array();
while($row = $result->fetch_assoc())
{
try
{
array_push($page, new Image($row['image_id'], $view_deleted_images));
}
catch(ImageNotFoundException $e)
{
throw $e;
}
}
return $page;
}
根據它們的流行度來選擇這些圖像的一個頁面。我已經編寫了一個Database
類來處理與數據庫的交互,還有一個Image
類,它包含關於圖像的信息。當我嘗試運行這個時,我得到一個錯誤。
Fatal error: Call to a member function fetch_assoc() on a non-object
$result
是mysqli的結果集,所以我很困惑,爲什麼這是行不通的。
$ result上的var_dump證實它是一個mysqli結果集? – erisco 2011-02-25 18:21:56