Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

Php if empty condition

Dear Experts,
I use PHP and MYSQL

I select data from database which has a column that has 3 diffrent kind of values.  Some text, empty value and Null value.

when I select that column from database like below

while($row = $result->fetch_assoc()) {
        	
	$mazeret= $row["mazeret"];

if (empty($mazeret)) {$mazeretim="X"; } else {$mazeretim="Y"; }

Open in new window


The result is Y for empty and filled rows,  only the NULL rows are X, however the empty rows must be X too.

what do you suggest I should do? Thank you
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

Dear Ryan,
Thank you,
Try this

$mazeretim = empty($row["mazeret"]) ? 'X' : 'Y';

Open in new window

BTW empty will return true for ""

If this is not happening it is possible you have a space in which case you do this

$mazeretim = empty(trim($row["mazeret"])) ? 'X' : 'Y';

Open in new window

Use trim to remove the spaces.