这是mysql查询
SELECT *
FROM users AS up
JOIN users AS u ON up.id = u.parent_id
JOIN users AS uc ON u.id = uc.parent_id
WHERE up.id =16
这是视图文件中的输出
<?php foreach($query->result() as $q): ?>
<?php echo $q->id; ?>
<?php endforeach; ?>
mysql结果给出3个级别的结果,但是在html中它只输出1个级别,并且是最后一个级别,但我需要在层次结构中呈现它
答案 0 :(得分:1)
将您的查询更改为:
SELECT up.id AS id1, u.id AS id2, uc.id AS id3
FROM users AS up
JOIN users AS u ON up.id = u.parent_id
JOIN users AS uc ON u.id = uc.parent_id
WHERE up.id = 16
然后,您可以访问id1
,id2
和id3
这三个级别:
<?php
foreach($query->result() as $q) {
echo $q->id1;
echo $q->id2;
echo $q->id3;
}
?>