у меня есть эта таблица
id | apple | banana | coconut | pear|
1 1 1 1 0
2 0 0 1 1
3 1 0 0 1
и этот sql-запрос
select tree
from ((select id, 'apple' as tree
from trees
where apple = 1
) union all
(select id, 'banana' as tree
from trees
where banana = 1
) union all
(select id, 'coconut' as tree
from trees
where coconut = 1
) union all
(select id, 'pear' as tree
from trees
where pear = 1
)
) t
where id = 1;
результат -
apple
banana
coconut
как мне написать это в php такя могу вывести результат
это то, что у меня есть до сих пор
$sql = " select tree
from ((select id, 'apple' as tree
from trees
where apple = 1
) union all
(select id, 'banana' as tree
from trees
where banana = 1
) union all
(select id, 'coconut' as tree
from trees
where coconut = 1
) union all
(select id, 'pear' as tree
from trees
where pear = 1
)
) t
where id = '$id'";
$result = mysqli_query($conn, $sql);
но я не знаю, что делать после этого, я не могу поставить цикл while или просто вывести его результатвыдает ошибку