function gotCate($pid = '0', $res = array(), $level = 0) { $res1 = getList('category', 0, 100, '*', 'pid=' . $pid); if (!empty($res1)) { foreach ($res1 as $k => $v) { $str = '<font color="red" >'; for ($i = 0; $i < $level; $i++) { $str .= '|-'; } $str .= '</font>'; $v['str_name'] = $str . '<font color="green" >' . $v['name'] . '</font>'; $res[] = $v; $res = gotCate($v['id'], $res, $level + 1); } } return $res; }
<?php checkLogin(); include MODEL . 'cate.func.php'; $res = gotCate(); // $res1 = getlist('category',0,100,'*','pid=0'); // $res = array(); // foreach($res1 as $k1=>$v1){ // $res[] = $v1; // $res2 = getlist('category',0,100,'','pid='.$v1['id']); // foreach($res2 as $k2=>$v2){ // $res[] = $v2; // $res3 = getlist('category',0,100,'','pid='.$v2['id']); // foreach($res3 as $k3=>$v3){ // $res[] = $v3; // } // } // } view(array('res' => $res));