note 35142 rejected from function.mysql-num-rows by pollita
| From: | pollita@php.net | Date: | Thu, 21 Aug 2003 03:35:40 +0000 |
| Subject: | note 35142 rejected from function.mysql-num-rows by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54795@lists.php.net to get a copy of this message | ||
Note Submitter: ipvariance@hotmail.com
----
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));