Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.