1
public function get_children($id)
{
$query = $this->db->query("SELECT
@last_id := id AS id,
parent_id,
FIO,
@depth := IF(parent_id = ".$id.", 1, @depth + 1) AS depth,
@first := IF(id = ".$id.", 'first', null) AS first
FROM
users
FORCE INDEX (index_parent_id, PRIMARY, index_both),
(SELECT @last_id := ".$id.", @depth := -1) vars
WHERE id = ".$id." OR parent_id = @last_id OR parent_id = ".$id."
");
return $query;
}
如何增加使用相鄰模型列表和此查詢的子節點的級別深度,現在它給了我的根父級(由函數中的id選擇)和他們的孩子,但不是更深,任何想法?增加MySQL查詢的深度
foreach($query->result() as $q){
if($q->first == 'first')
{
$parent_id = $q->parent_id;
break;
}
}
function print_list($array, $parent=0) {
print "<ul>";
foreach ($array as $row) {
if ($row->parent_id == $parent) {
print "<li>$row->FIO";
print_list($array, $row->id); # recurse
print "</li>";
} }
print "</ul>";
}
echo print_list($query->result(), $parent_id);
然後我呈現在視圖文件...請幫助或什麼改變或看到增加MySQL查詢的深度任何建議。
謝謝,這幫了我 – 2012-07-10 17:08:05