Forum Moderators: coopster

Message Too Old, No Replies

"supplied argument is not a valid MySQL result resource"

         

DrDoc

9:35 am on Mar 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm doing this:

$lookup = mysql_query("...");
$num = mysql_num_rows($lookup);
if($num) {
do stuff...
}

It's worked fine before, but now I get this:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /path_to_file on line #

It works if the query returns something, of course...

Fischerlaender

9:56 am on Mar 17, 2003 (gmt 0)

10+ Year Member



This should stop the warning:

$lookup = mysql_query("..."); 
if($lookup) {
$num = mysql_num_rows($lookup);
if($num) {
do stuff...
}
}

DrDoc

10:01 am on Mar 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shouldn't it be enough to just do this then?

if($lookup) {
...
}

Or are there times when $lookup will be set to something, but still not return any rows? If so, I guess I could just do:

if($lookup && mysql_num_rows($lookup)) {
...
}

It's just that it's worked before. You can even find examples on php.net and mysql.com that suggest that method...

Fischerlaender

12:56 pm on Mar 17, 2003 (gmt 0)

10+ Year Member



$lookup = mysql_query("...");

$lookup is false, if there is an error in your query: wrong syntax ("SELCET"), not existing field name, ..

$num = mysql_num_rows($lookup);

$num is false, if there where no rows from the $lookup-query: "SELECT * WHERE 1=-1", table is empty, and so on

$lookup = mysql_query("...");[/ 
if($lookup && mysql_num_rows($lookup)) {
...
}

This should work, because if $lookup is false the second part isn't executed any more.