如何根据父ID使用php mysql获取treeview

时间:2018-08-16 09:28:21

标签: treeview

$query = mysqli_query($con, "SELECT * from users "); 
while($row = mysqli_fetch_object($query))
{
    $sub_data['id'] = $row->user_id;
    $sub_data['name'] = $row->username;
    $sub_data['parent_id'] = $row->parent_id;

    $data[] = $sub_data;
}

foreach($data as $key => &$value) 
{
    $output[$value['id']] = &$value;
}

foreach($data as $key => &$value) 
{
    if($value['parent_id'] && isset($output[$value['parent_id']])) 
    {
        $output[$value['parent_id']]['node'][] = &$value;
    }   
} 

我想使用这种查询“ SELECT * from parent_id ='20'的用户”。 但是我没有在这个parent_id上获得所有树成员

0 个答案:

没有答案