Jump to content

[SOLVED] mysql_num_rows() Warning


conker87

Recommended Posts

I'm just wondering how to get rid of this warning:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/conker87/public_html/<page> on line <line>

If the number of rows is equal to zero. I've tried inserting this:

 

   if (mysql_num_rows($result) == 0) { $rowcount = 0; }
   else { $rowcount = mysql_num_rows($result); }

But it still shows. Any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/71270-solved-mysql_num_rows-warning/
Share on other sites

You could try my favorite "tertiary" operator:

 

$rowcount = (mysql_num_rows($result)) ? (mysql_num_rows($result)) : '0';

 

my_sql_numrows will return either the number of rows or a 'false'. So if it returns a false you assign $rowcount a '0' if mysql_num_rows returns anything else, you can assign $rowcount that number. In you code you are using mysql_num_rows as if it exists, but if it has no rows (i.e., a 'false' return) then it will not exist.

It means that there is something wrong with your query. Put a die statement at the end of it.

 

EX.

$result = mysql_query($query)or die(mysql_error());

 

That will tell you what went wrong.

I noticed that I'd spelt the table slightly wrong.  Thanks anyway.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.