可能重复:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
它引用的行是调用mysql_fetch_array()函数的行。当运行phpmyadmin时,查询工作正常。它也不会抛出错误。任何帮助都将不胜感激。

$query = "select distinct s.time, s.parameter, s.data, t.units from alertData as s, parameters as t where s.parameter like '%Airtemp_Avg%' and s.staID = 'WS_001_UHC' and s.interval_min = 15 and t.parameter like '%Airtemp_Avg%' and unix_timestamp(s.time) >= (unix_timestamp(now()) - 86400) order by time desc";
$results = mysql_query($query) || die(mysql_error());
$dataCnt = 0;
while($info = mysql_fetch_array($results)) {
    //15 Min data
    if(($dataCnt == 0) && (getTimestamp($info['time']) >= ($now - 4500)))
       $data15['temp'] = $info['data'];
    else
       $data15['temp'] = '-';

    $dataCnt++;
}

最佳答案

移除|| die (mysql_error())之后的mysql_query()。它被评估为bool,这就是错误的原因。
编辑:
正如bfavareto所指出的,您可以使用OR来代替。这只是php的另一个不一致之处。在PHP Documentation about Logical Operators中阅读更多信息(查看第一个代码示例的注释)。

关于php - PHP警告:mysql_fetch_array()期望参数1是资源, bool 给定,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12414606/

10-11 14:04