Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 错误:mysql\u fetch\u array():提供的参数不是有效的mysql结果资源_Php_Mysql_Chat_Send_Fetch - Fatal编程技术网

Php 错误:mysql\u fetch\u array():提供的参数不是有效的mysql结果资源

Php 错误:mysql\u fetch\u array():提供的参数不是有效的mysql结果资源,php,mysql,chat,send,fetch,Php,Mysql,Chat,Send,Fetch,我收到错误“mysql\u fetch\u 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'&

我收到错误“mysql\u fetch\u 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];
}
$result=mysql\u查询(“按时间描述限制0,10从聊天订单中选择*);
$messages=array();
while($row=mysql\u fetch\u数组($result)){
$messages[]=“”.$row[name]。“-”.date('g:iam,dy',$row[time])。“”.$row[message]。”;
//最后发布日期
$old=$row[时间];
}
//以升序显示消息,因此最新消息将位于底部
对于($i=9;$i>=0;$i--){
回显$messages[$i];
}

您的查询中有一个错误

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


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

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

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

你可以用

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

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

我猜想您的查询失败了;但你没有检查它,只是假设它起作用了。您应该检查来自
mysql\u query
的返回,并适当地处理它;您将在
mysql\u error
中找到该问题的全部详细信息。的可能重复。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果您选择PDO,您在这里做过任何基本调试吗?使用
mysql\u error
函数查看您的查询出了什么问题。如果你在已经回复的网站上搜索数百万个副本,这也会有所帮助。你的下一个注意事项是:使用未定义的常量名称-假定为“name”和。。。
$row = mysql_num_rows($result);
echo($row);