mysql_num_rows returns 1 with NULL result
Posted: Thu May 13, 2010 12:26 pm
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
Can someone explain this behavior and why mysq_num_rows($result) didn't return a zero value.
Thanks,
Tom