Is null in php mysql?

Here is the below Code:

$query = mysql_query("SELECT * FROM tablex");

if ($result = mysql_fetch_array($query)){

    if ($result['column'] == NULL) { print ""; }
    else { print ""; }
}

If the values are NOT NULL i still get the uncheked box. Am i doing something wrong from above, shoudnt $result['column'] == NULL work?

Any Ideas?

asked Oct 16, 2009 at 5:33

Angel.King.47Angel.King.47

7,79414 gold badges59 silver badges84 bronze badges

4

Use is_null or === operator.

is_null($result['column'])

$result['column'] === NULL

answered Oct 16, 2009 at 5:42

The ChairmanThe Chairman

7,0362 gold badges37 silver badges43 bronze badges

1

How about using

if (empty($result['column']))

answered Oct 16, 2009 at 5:53

fernybfernyb

9731 gold badge8 silver badges11 bronze badges

2

Make sure that the value of the column is really NULL and not an empty string or 0.

answered Oct 16, 2009 at 5:46

Tomas MarkauskasTomas Markauskas

11.3k2 gold badges32 silver badges35 bronze badges

2

I think you want to use

mysql_fetch_assoc($query)

rather than

mysql_fetch_row($query)

The latter returns an normal array index by integers, whereas the former returns an associative array, index by the field names.

answered Oct 16, 2009 at 5:42

JoelJoel

11.2k17 gold badges61 silver badges72 bronze badges

1

Sometimes, when I know that I am working with numbers, I use this logic (if result is not greater than zero):

if (!$result['column']>0){

}

answered Dec 5, 2015 at 19:58

Is null in php mysql?

AndrewAndrew

7,46113 gold badges59 silver badges114 bronze badges

1

Is null in php mysql?


This MySQL tutorial explains how to use the MySQL IS NULL condition with syntax and examples.

Description

The MySQL IS NULL Condition is used to test for a NULL value in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax

The syntax for the IS NULL Condition in MySQL is:

expression IS NULL

Parameters or Arguments

expressionThe value to test if it is a NULL value.

Note

  • If expression is a NULL value, the condition evaluates to TRUE.
  • If expression is not a NULL value, the condition evaluates to FALSE.

Example - With SELECT Statement

Let's look at an example of how to use MySQL IS NULL in a SELECT statement:

SELECT *
FROM contacts
WHERE last_name IS NULL;

This MySQL IS NULL example will return all records from the contacts table where the last_name contains a NULL value.

Example - With INSERT Statement

Next, let's look at an example of how to use MySQL IS NULL in an INSERT statement:

INSERT INTO contacts
(contact_id, contact_name)
SELECT account_no, supplier_name
FROM suppliers
WHERE category IS NULL;

This MySQL IS NULL example will insert records into the contacts table where the category contains a NULL value.

Example - With UPDATE Statement

Next, let's look at an example of how to use MySQL IS NULL in an UPDATE statement:

UPDATE contacts
SET last_name = 'TBD'
WHERE last_name IS NULL;

This MySQL IS NULL example will update records in the contacts table where the last_name contains a NULL value.

Example - With DELETE Statement

Next, let's look at an example of how to use MySQL IS NULL in a DELETE statement:

DELETE FROM contacts
WHERE last_name IS NULL;

This MySQL IS NULL example will delete all records from the contacts table where the last_name contains a NULL value.

Is NULL in MySQL?

Conceptually, NULL means “a missing unknown value” and it is treated somewhat differently from other values. Because the result of any arithmetic comparison with NULL is also NULL , you cannot obtain any meaningful results from such comparisons. In MySQL, 0 or NULL means false and anything else means true.

Is NULL in PHP?

The is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.

IS NOT NULL php MySQL?

By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field.

Is NULL or empty MySQL?

The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value. mysql> SELECT * FROM ColumnValueNullDemo WHERE ColumnName IS NULL OR ColumnName = ' '; After executing the above query, the output obtained is.