-1

我收到错误“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];
}
4

2 回答 2

1

Theres an error in your query.

Try to output the error with mysql_error(), e.g.:

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

This will stop the script and show the sql error.

于 2013-08-29T12:53:43.160 回答
0

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

您可以使用 mysql_error() 找出错误所在

或者

您可以使用

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

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

于 2013-08-29T13:13:10.403 回答