noy-hadar
noy-hadar

Reputation: 169

How do I get Isset() to ignore an empty field?

Not sure if I'm taking the right approach here. I want something to display only if a value is set in the field. I've tested this several ways.
1) If the value is set, then it displays correctly.
2) If I make up some random variable, then "N/A" is correctly displayed. But,
3) If the value in the field has NO set value, the echoed text still appears and of course without any set value.

if (isset($row['DATE'])) {
    echo "Dated: {$row['DATE']} <br />" ;
} else {echo "N/A" ; }

So what am I missing? How do I get this code to recognize and ignore an empty field?

Upvotes: 0

Views: 592

Answers (3)

Mapachito
Mapachito

Reputation: 1

I would use another if checking if the value is not set (!isset($row['DATE'])) Rgds.

Upvotes: 0

Nebojsa Susic
Nebojsa Susic

Reputation: 1260

You looking for empty() function. They will return false if variable is empty or is not set.

Upvotes: 0

Jim
Jim

Reputation: 22656

empty() will return true if the given variable is not set or evaluates to false:

if (!empty($row['DATE'])) {
    echo "Dated: {$row['DATE']} <br />" ;
} else {echo "N/A" ; }

Upvotes: 1

Related Questions