SQL调用继续返回错误

时间:2013-05-16 03:08:37

标签: php mysql

下面的SQL调用一直在返回:

致命错误:在第86行的/home/content/76/10930776/html/apprentice/report.php中调用非对象上的成员函数fetch_assoc()

$sql = "select sum(".$column.") as totalmeetings,username from data where datediff(max(dateinput),min(dateinput)) <= ".$daysdifference." group by username ";
echo $sql;
$result = $mysqli->query($sql);



while($pcresult = $result->fetch_assoc())//line 86
    {

}

我做错了什么? SQL调用打印出来像这样:

select sum(prospects1stmeeting) as totalmeetings,username from data where datediff(max(dateinput),min(dateinput)) <= 500 group by username 

2 个答案:

答案 0 :(得分:1)

尝试此查询

select sum(prospects1stmeeting) as totalmeetings,username from data  
group by username 
having datediff(max(dateinput),min(dateinput)) <= 500

答案 1 :(得分:0)

看看你是如何尝试访问结果的:

$result = $mysqli->query($sql);
while($pcresult = $result_percentile->fetch_assoc())//line 86
{

}

$ result和$ results_percentile不是一回事。你应该试试:

$result = $mysqli->query($sql);
while($pcresult = $result->fetch_assoc())//line 86
{

}

除非您没有显示整个代码。

修改

但是,由于您编辑的问题不再反映这个答案,答案仍然是您尝试访问非对象。这意味着$ result不会产生可以作为关联数组读取的数据。