[英]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
attempting to implement a facebook style pagination and i've been getting this error? 试图实现Facebook风格的分页,我一直收到这个错误?
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
,
I'm not entirely sure what this really means, but I can't find a fix for it from googling, anything silly mistakes that stand out? 我不完全确定这是什么意思,但我无法通过谷歌搜索找到解决方法,任何愚蠢的错误都能脱颖而出? here's the code :
这是代码:
<?php
include('functions.php');
if(isset($_POST['lastmsg']) &&is_numeric($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$query = mysql_query("SELECT * FROM links WHERE id>'$lastmsg' ORDER BY id ASC LIMIT 9 ");
while($result = mysql_fetch_array($query))
{
$msg_id=$result['id'];
$message=$result['link'];
?>
<li> <?php echo $message; ?> </li>
<?php
}
?>
<?php
if(mysql_num_rows($result)==9){
?>
<div class="facebook_style" id="facebook_style">
<a id="<?php echo $message; ?>" href="#" class="load_more" >
Show Older Posts <img src="arrow1.png" /></a> </div>
<?php
}else {
echo ' <div id="facebook_style">
<a id="end" href="#" class="load_more" >No More Posts</a>
</div>';
}
}
?>
You want to pass mysql_num_rows()
your $query
value rather than your $results
value. 您希望传递
mysql_num_rows()
$query
值而不是$results
值。 (Or you want to refactor your code to name $query
to something else like $query_result
and pass that to mysql_num_rows()
.) (或者你想重构你的代码,将
$query
命名$query
$query_result
并将其传递给mysql_num_rows()
。)
mysql_num_rows()
expects a MySQL result resource, which in your case is returned by mysql_query()
, which you've assigned to $query
. mysql_num_rows()
需要MySQL结果资源,在您的情况下由mysql_query()
返回,您已将其分配给$query
。
$result
, in contrast, is just an array representing a single row of the result. 相反,
$result
只是一个表示结果的单行的数组。 (So a better refactoring might be to rename $result
to $row
and rename $query
to $result
. Then you can leave your call to mysql_num_rows()
as is.) (所以更好的重构可能是将
$result
重命名$result
$row
并将$query
重命名$query
$result
。然后你可以按原样调用mysql_num_rows()
。)
mysql_num_rows()
expects a result resource (in your case $query
) rather than a row pulled from mysql_fetch_array()
. mysql_num_rows()
期望结果资源(在您的情况下是$query
)而不是从mysql_fetch_array()
提取的行。
if(mysql_num_rows($query )==9) {
// etc...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.