Page 1 of 1

working with null in php

Posted: Wed Feb 08, 2012 2:47 pm
by merofelde
I have three fields in a table.
the last field does not always have data in it.
I want to display only the rows where the third field is empty ( or NULL )

Code: Select all

//connection strings
$result = mysql_query("SELECT field1, field2, field3 FROM tablename WHERE field3 IS NULL");
while($row = mysql_fetch_array($result))
{
echo $row['field1'] . $row['field2'];
echo "<hr></hr>";
}
//close connection
I am trying to generate a list of those records that are missing data from field3.
Any thoughts?

Re: working with null in php

Posted: Wed Feb 08, 2012 2:54 pm
by Celauran
Is the field allowed to be NULL? You could try WHERE field3 = ''

Re: working with null in php

Posted: Wed Feb 08, 2012 3:02 pm
by merofelde
Celauran wrote:Is the field allowed to be NULL? You could try WHERE field3 = ''
the field does not have to contain data. It is an optional field.
So I could try WHERE field3 = NULL ???

Re: working with null in php

Posted: Wed Feb 08, 2012 3:04 pm
by Celauran
See if the schema allows NULL or not. Empty and NULL aren't the same. I'd still check for WHERE field3 = ''

Re: working with null in php

Posted: Wed Feb 08, 2012 3:11 pm
by merofelde
Celauran wrote:See if the schema allows NULL or not. Empty and NULL aren't the same. I'd still check for WHERE field3 = ''
went to phpmyadmin and put a check in the box next to Null.
and changed the WHERE field3 = ' '" and it worked.
Thanks :-)