php 警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5473981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
提问by Corrie
Possible Duplicate:
PHP: Warning: sort() expects parameter 1 to be array, resource given
Please help,
请帮忙,
I get following Error:
我收到以下错误:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in......
警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在......
Here is my Query:
这是我的查询:
$query = "SELECT ListNumber FROM residential";
$result1 = mysql_query($query);
if (mysql_num_rows($result1) >10){
$difference = mysql_num_rows($result1) - 10;
$myQuery = "SELECT * FROM `residential` ORDER BY `id` LIMIT 10,". $difference;
$result2 = mysql_query($myQuery);
echo $result2;
$replace = str_replace(", "," | ", $result2);
while ($line = mysql_fetch_array($result2, MYSQL_BOTH))
回答by Codecraft
Your query ($myQuery) is failing and therefore not producing a query resource, but instead producing FALSE.
您的查询 ($myQuery) 失败,因此不会生成查询资源,而是生成 FALSE。
To reveal what your dynamically generated query looks like and reveal the errors, try this:
要显示动态生成的查询的外观并显示错误,请尝试以下操作:
$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());
The error message will guide you to the solution, which from your comment below is related to using ORDER BY on a field that doesn't exist in the table you're SELECTing from.
错误消息将引导您找到解决方案,根据您下面的评论,该解决方案与在您从中选择的表中不存在的字段上使用 ORDER BY 相关。
回答by Hammerite
The code you have posted doesn't include a call to mysql_fetch_array()
. However, what is most likely going wrong is that you are issuing a query that returns an error message, in which case the return value from the query function is false
, and attempting to call mysql_fetch_array()
on it doesn't work (because boolean false
is not a mysql result object).
您发布的代码不包括对mysql_fetch_array()
. 但是,最有可能出错的是您发出一个返回错误消息的查询,在这种情况下,查询函数的返回值是false
,并且尝试调用mysql_fetch_array()
它不起作用(因为 booleanfalse
不是 mysql结果对象)。
回答by kavita
mysql_fetch_array()
expects parameter 1 to be resource boolean given in php error on server if you get this error : please select all privileges on your server
. u will get the answer..
mysql_fetch_array()
预计参数1是在服务器上的PHP的错误给出,如果你得到这个错误资源布尔: please select all privileges on your server
。你会得到答案..
回答by Wh1T3h4Ck5
$result2 is resource link not a string to echo
it or to replace some of its parts with str_replace()
.
$result2 是资源链接,而不是指向echo
它的字符串或将其某些部分替换为str_replace()
.
回答by ukpatel
This error comes when there is error in your query syntax check field names table name, mean check your query syntax.
当您的查询语法检查字段名称表名称中有错误时会出现此错误,这意味着检查您的查询语法。