Jump to content

[SOLVED] mysql_num_rows(): supplied argument is not a valid MySQL result resource error


Sparrow

Recommended Posts

I keep getting this error over and over no matter what I do: mysql_num_rows(): supplied argument is not a valid MySQL result resource.  It say it has to do with line 296:  Here is line 296 and the lines around it.

 

$result = mysql_query('SELECT * FROM `users` ORDER BY `users`.`signup_date` DESC LIMIT 0, 10 ');

$num = mysql_num_rows($result);

$i = 0;

?> 

 

I already tried putting OR die(mysql_error()); after 0, 10 ').  That takes away the error but then the code dosen't work.

 

 

the issue is most likely the space between 0, and 10; it could also be the trailing space in the query.  SQL can be somewhat finnicky.  try this:

 

$result = mysql_query('SELECT * FROM `users` ORDER BY `users`, `signup_date` DESC LIMIT 0,10') or die(mysql_error());

 

also, and this may sound silly but you never know, make sure you've got a connection to the DB open and a DB selected.

the issue is most likely the space between 0, and 10; it could also be the trailing space in the query.  SQL can be somewhat finnicky.  try this:

 

$result = mysql_query('SELECT * FROM `users` ORDER BY `users`, `signup_date` DESC LIMIT 0,10') or die(mysql_error());

 

also, and this may sound silly but you never know, make sure you've got a connection to the DB open and a DB selected.

 

I tried this SQL qery but then it started reading users as a column so I changed it to:  mysql_query('SELECT * FROM `users` ORDER BY `signup_date` DESC LIMIT 0,10') or die(mysql_error()); 

 

Than I get the error Unknown column 'signup_date' in 'order clause'.  signup_date is a column though, so why isn't it working.  And yes I am pretty sure there is a connection the the database base  because at the very top of the coding I put    include 'db.php';    . db.php has the datase connection information.  I used this same file on my old website and it works.

 

if it's telling you the column doesn't exist, it's because it doesn't exist.  could be that you've misspelled it, could be that the server this application is sitting on has a different db design, who knows?  have a look to make sure.  SQL doesn't lie, even though sometimes even the most minor detail makes it seem like it is.

 

alternatively, you could try removing the backticks and see if that helps.  it likely won't though.

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.