BR
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
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
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"; }
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this
$mazeretim = empty($row["mazeret"]) ? 'X' : 'Y';
BTW empty will return true for ""
If this is not happening it is possible you have a space in which case you do this
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';
Use trim to remove the spaces.
ASKER
Thank you,