This is how my table looks like..
id col1 col2
---------------
1 a x
2 NULL y
3 NULL z
4 NULL t
col1 has a default value of NULL
.
I want to use col1 data If col1 is not null, otherwise use col2 data.
function something($col1,$col2)
{
if(is_null($col1) == true)
$var = $col2
else
$var = $col1
return $var;
}
function something2($col1,$col2)
{
if($col1 === NULL)
$var = $col2
else
$var = $col1
return $var;
}
Here is my problem. Both of these functions returns $col2 values. But as you can see in first row, col2 column is not null. What am I doing wrong? UPDATE: Looking for a solution with PHP and I need both col1 and col2 values.
Also I want to learn, Does using NULL values is the best practice for this example?