Re: problems with mysql_query() and mysql_num_rows()
| From: | Cody Caughlan | Date: | Mon, 10 Jul 2000 16:32:54 +0000 |
| Subject: | Re: problems with mysql_query() and mysql_num_rows() | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-1011@lists.php.net to get a copy of this message | ||
mysql_num_rows() will only work if there were any rows returned from the
SQL statement.
Like this:
$res = mysql_db_query("database", " some SQL statement");
$nrows = mysql_num_rows($res);
this will only work if $res contains a valid SQL set. It doesnt really have
to do with whether its true or not. How could mysql_num_rows work on a
true/false scale? what you should do is this:
$res = mysql_db_query("database", " some SQL statement");
if( mysql_errno() )
{
$err = mysql_error();
echo "$err";
}
if (! mysql_errno()) $num_rows = mysql_num_rows($res);
by putting in that error-checking statement you can see why your
SQL statement is failing, hence the failure of mysql_num_rows();
/Cody
Jeffrey A Schoolcraft wrote:
> I'm using some code off of webmonkey to do user validation with a mysql
> database. They use mysql_num_rows to make sure the result set wasn't 0.
> PHP is complaining:
>
> Warning: Supplied argument is not a valid MySQL result resource in
> /usr/local/apache/htdocs/auth.php on line 48
>
> And it authorizes everyone.
>
> So I did some research and set mysql_query() equal to a value, and then
> tried to do if (mysql_query()) assuming a false value means it won't
> validate, but that didn't work either.
>
> I'd appreciate any help.
>
> Jeffrey Schoolcraft