Jump to content

[SOLVED] mysql_num_rows(): supplied argument is not a valid


lalabored

Recommended Posts

I get this error...

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in readpm.php on line 22

 

With this code

 

$q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1";
$rs = mysql_query($q);
$rscount = mysql_num_rows($rs);

 

Can someone tell me what's wrong?

Link to comment
Share on other sites

hi,

i also get this error sometimes. in my case, i get this error when my SQL statement is wrong or when my database is empty. so you too check that.

 

try printing the select statement and run same statement directly in the database.

Link to comment
Share on other sites

$q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1";
$rs = mysql_query($q);
$rscount = mysql_num_rows($rs);

 

The major problem I can see is that you're not checking to make sure that the mysql_query() function executed cleanly, when it doesn't $rs will be set to false.

 

You could try changing it to something like this:

 

$q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1";
$rs = mysql_query($q);
if (!$rs) { die("Could not query the database!"); }
$rscount = mysql_num_rows($rs);

 

The problem is that this is quite messy and I'm assuming that you haven't checked to make sure your mysql_connect and mysql_select_db functions have been executed cleanly.

 

I've written a short example on how to do the basics of this:

 

http://kritical.info/?p=8

 

I've written an example of how to do this a bit cleaner, although my example still uses die() if there is an error you could quite easily change this to your hearts content,

 

I hope this helps, cheers...

Link to comment
Share on other sites

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.