【问题标题】:Error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource错误:mysql_fetch_array():提供的参数不是有效的 MySQL 结果资源
【发布时间】:2013-09-01 22:06:30
【问题描述】:

我收到错误“mysql_fetch_array():提供的参数不是有效的 MySQL 结果资源...”。在与此 mysql 查询有关的行上。

$result = mysql_query("select * from chat order by time desc limit 0,10");
$messages = array();

while($row = mysql_fetch_array($result)){

   $messages[] = "<div class='message'><div class='messagehead'>" . $row[name] . " - " . date('g:i A M, d Y',$row[time]) . "</div><div class='messagecontent'>" . $row[message] . "</div></div>";
   //The last posts date
   $old = $row[time];
}
//Display the messages in an ascending order, so the newest message will be at the bottom
for($i=9;$i>=0;$i--){
   echo $messages[$i];
}

【问题讨论】:

标签: php mysql chat send fetch


【解决方案1】:

您的查询中有错误。

尝试用mysql_error()输出错误,例如:

$result = mysql_query("select * from chat order by time desc limit 0,10") or die(mysql_error());

这将停止脚本并显示 sql 错误。

【讨论】:

    【解决方案2】:

    这意味着您的查询没有执行,其中有一些错误。

    你可以使用mysql_error()找出错误是什么

    你可以使用

    $row = mysql_num_rows($result);
    echo($row);
    

    看看它是否返回任何值。如果它返回 1 或值 >1,则表示您的查询工作正常,否则不执行查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 2011-03-30
      • 2013-05-08
      • 1970-01-01
      相关资源
      最近更新 更多