参见英文答案 > mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result????????????????????????????????????32个
我正在尝试执行一些查询以获取有关某些图像的信息页面.我写了一个函数
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结果集,所以我很困惑为什么这不起作用.