mysql_num_rows returns 1 with NULL result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tcl4p
Forum Newbie
Posts: 15
Joined: Mon Apr 02, 2007 9:28 am

mysql_num_rows returns 1 with NULL result

Post by tcl4p »

I have a simple query "select ResultTemplateID from mam_template_links where TriggerTemplateID = 23", which when run in phpmyadmin returns 0 rows. I would expect when I test (mysql_num_rows($result) >0) it would return false, but it does not. When I did a display of echo mysql_num_rows($result) it shows a value of one (1). The data type of ResultTemplateID is set to int and Null is not allowed. I next added some code to set the value of mysql_num_rows($result) to a variable as in $r = mysql_num_rows($result) and then put an echo $r, but before running the query I set the value of $r =0. After the query ran the echo of $r showed no value, not even the zero to which it was set. I then added code to test $r==NULL, which returned true. So it appears mysql_num_rows had a value of NULL which caused it to return 1, but WHY?
Can someone explain this behavior and why mysq_num_rows($result) didn't return a zero value.

Thanks,
Tom
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: mysql_num_rows returns 1 with NULL result

Post by mikosiko »

please post the code that you are using
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: mysql_num_rows returns 1 with NULL result

Post by Weirdan »

Please post your code.
Post Reply