View Full Version : equality for null from mysql

03-05-2008, 04:13 AM
How do I make a condition when a certain field of a mysql database is null. I tried empty($row['population']), !isset($row['population']), and $row['population'] == null. All of them don't work.

$result = mysql_query('SELECT city FROM town WHERE city="New York"');
$row = mysql_fetch_array($result);

if (empty($row['population']))

EDIT: Found there is something wrong with my query!

03-05-2008, 04:20 AM
Well what is wrong with your query? To see if its null you can do

if($row['population'] == NULL)

03-05-2008, 04:29 AM
Well what is wrong with your query?
Just a guess, but it might be that the field isn't selected. I wonder if that edit was intended to mean the OP solved it.

03-05-2008, 05:23 AM
Yup, I solved it.

The query did not select the field I want to check if it is null. But now I have another question. But I will put it in another thread.