note 35142 added to function.mysql-num-rows
| From: | ipvariance at hotmail dot com | Date: | Thu, 21 Aug 2003 03:13:06 +0000 |
| Subject: | note 35142 added to function.mysql-num-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-54794@lists.php.net to get a copy of this message | ||
Seeing weird "$var is not a valid mysql result resource" when trying to find the number of
rows?
When I just started working in php it was common for me to do somthing like -
$var = mysql_query($q, $link_id);
if (!mysql_num_rows($var)) {
// error
}
If there are no rows returned php will warn you that its not a valid mysql result resource when
logically it is. What it is doing - is when no results are returned its putting basically nothing
into $var - then mysql_num_rows tries to use nothing as a mysql result resource which of course it
can't.
A really quick way to get arround this is with -
$numrows = mysql_num_rows(mysql_query($q, $link_id));
----
Manual Page -- http://www.php.net/manual/en/function.mysql-num-rows.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35142
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35142&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35142&report=yes