raz0r — 2008-11-15T14:56:02-05:00 — #1
the IF statement can't recognize a "NULL" in a column of INT?
FETCH c INTO x;
# lets say the first x = NULL.
IF x = NULL THEN
That IF statement won't execute
IF x = 1 THEN
the If statement executes. What's up with that?
felgall — 2008-11-15T15:37:27-05:00 — #2
NULL is never equal to anything else not even NULL.
use ISNULL() to test if something is NULL.
r937 — 2008-11-15T15:44:59-05:00 — #3
i prefer COALESCE
mittineague — 2008-11-15T15:45:19-05:00 — #4
Are you sure it's NULL and not empty?
@felgall, I use
if ( mysql_result($result,$i,'fieldname') != NULL )
echo "..... mysql_result($result,$i,'fieldname') .....
and it seems to work OK. That is, it doesn't echo the "....."s when the field is NULL
felgall — 2008-11-15T17:37:42-05:00 — #5
A mySQL NULL value and a PHP NULL value are not exactly the same thing and it may have something to do with the difference between the way NULLs are implemented in both. I think you'll find that trying to compare to NULL within the SQL is where it will not work. I was assuming that the query was with regard to testing the field for NULL in the SQL itself.
mittineague — 2008-11-15T19:08:13-05:00 — #6
:d'oh: of course. I'm too darn PHP-centric at times.
I tried finding info on FETCH without any luck (yet), but I did see documentation for queries like
Where field IS NULL
so the "IS" instead of the "=" is what to use for MySQL as far as NULLs are concerned.
felgall — 2008-11-15T19:46:05-05:00 — #7
FETCH is used where you have opened a cursor to hold the results of a query and you want to return the next record from the results in the cursor.
Either x IS NULL or ISNULL(x) should work to test if x contains null. I suppose which of them to use would depend on which fitted better with the way the surrounding SQL is coded. I wouldn't expect it would make any difference to the efficiency of the processing (although I could be wrong as I have never actually tested it).
r937 — 2008-11-15T20:18:01-05:00 — #8
and every other database system, too
raz0r — 2008-11-17T11:57:16-05:00 — #9
thanks everyone, i understand now, thanks for the suggestions.