views:

332

answers:

2

Why does mysql_num_rows($result) return 1 even if $result returns empty result set?

$resut=mysql_query("select * from tablename where column1='$memberid' and (TIME_TO_SEC(TIMEDIFF(NOW(),when_submit))/60<2)")or die(mysql_error());
$count=mysql_num_rows($result);

when I echo $count, I get

1

.

+4  A: 

You have a spelling error in your code. You store the result of the call to mysql_query() in the variable called $resut. That should be $result, since that is what you are passing in the call to mysql_num_rows()

Roland Bouman
Very sharp eyes! +1
o.k.w
A: 

You are obviously running 2 queries on the same page. I would advise returning them to different $result variables. $result1, $result2 if need be. In the past I've had instances where the $result did not get updated even though there wasn't a spelling issue (though I can't remember the cause).

MindStalker