...

View Full Version : mysql_num_rows - returns 0



ChantCd
08-25-2011, 02:03 AM
I have a rather complex query, with about 3 joins.

It returns 12 rows when I run the SQL code manually via phpMyAdmin.

However, when I paste it in my webpage, run the query, and call the

mysql_num_rows()

function, it returns 0!

To double-check, I had the program output the text of the query (with variables filled in, etc.) whenever it gave me "the bad news" that no results were found. I pasted that code into phpMyAdmin and, sure enough, 12 rows!

The PHP script should be finding 12 rows as well, but it doesn't seem to be!

The apparent contradiction, and not understanding this behavior of mysql_num_rows, is having me figuratively pulling my hair out. It makes no sense!

Has anyone else had this problem? If my last 1/2 hour of Googling is any indication, I'm guessing "no".

Thanks in advance,

Matthew

firepages
08-25-2011, 02:59 AM
can you post your code for the call .. e.g.


$q=mysql_query($sql);
echo mysql_num_rows($q);

webdev1958
08-25-2011, 03:17 AM
To double-check, I had the program output the text of the query (with variables filled in, etc.) whenever it gave me "the bad news" that no results were found. I pasted that code into phpMyAdmin and, sure enough, 12 rows!

The PHP script should be finding 12 rows as well, but it doesn't seem to be!


If your query returns the correct results in phpMyAdmin and not in php then there is a bug in your php code.

To help see what is happening can you do the following:



$query = "select blah blah......";

echo $query; die();

and post the output of the echo statement.

JamesOxford
08-25-2011, 04:24 AM
can you post the sql? That will probably tell a lot more

...webdev's suggestion will do the same thing.

tangoforce
08-25-2011, 03:53 PM
Firepages!!! You're alive! :thumbsup:

OMG... I bow to thee great oracle of WAMP on USB :D

PS When are you gonna update your bl**dy website with some more cool stuff?!?!?!?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum