View Full Version : mysql_result and <NULL>

10-27-2006, 06:59 AM
so, i want to grab the value of a sql entry. but the thing is, sometimes this value is <NULL>. i thought, no biggy, i'll just have an if statement:

if (is_numeric(mysql_result($query, 0))) {
//do something
} else {
//do something else using mysql_result($category_id_query, 0);
however, this doe not work. i get this error:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3

is there a way to check to see if mysql_result() is <NULL> without throwing an error??

10-27-2006, 07:33 AM
Use the MySQL function ISNULL(). (http://dev.mysql.com/doc/refman/4.1/en/comparison-operators.html)

10-27-2006, 08:32 AM
Hi you could use also php functions to check mysql result

mysql_num_rows or

10-27-2006, 03:41 PM
awesome, thanks, mysql_num_rows worked. the problem with is_numeric or is_null is that mysql_result would throw the error no matter what. using mysql_num_rows let me check to see if there was anything in it before using mysql_result