public
function
digui(){
$crr
=
$this
->db->get('category')->result_array();
$list
['type'] =
$this
->nolimit(
$crr
,0,0);
$this
->load->view('list1',
$list
);
}
public
function
nolimit(
$crr
,
$p_id
,
$level
){
static
$arr
=
array
();
foreach
(
$crr
as
$v
){
if
(
$v
['parent_id']==
$p_id
){
$v
['level'] =
$level
;
$arr
[] =
$v
;
$this
->nolimit(
$crr
,
$v
['cat_id'],
$level
+1);
}
}
return
$arr
;
}
<td><?PHP
echo
str_repeat
(' ',
$val
['level'])?><?php
echo
$val
['cat_name']?></td>
public
function
sel_child(
$p_id
){
$arr
=
$this
->sel_son(
$p_id
);
foreach
(
$arr
as
$k
=>
$v
){
$tmp
=
$this
->sel_son(
$v
['cat_id']);
foreach
(
$tmp
as
$kk
=>
$vv
){
$tmp2
=
$this
->sel_son(
$vv
['cat_id']);
$tmp
[
$kk
]['childs'] =
$tmp2
;
}
$arr
[
$k
]['child'] =
$tmp
;
}
return
$arr
;
}
public
function
sel_son(
$id
){
$this
->db->where(
"parent_id=$id"
);
return
$this
->db->get(self::
$cate
)->result_array();
}
public
function
lists(){
$p_id
= 0;
$brr
['type'] =
$this
->Home_model->sel_child(
$p_id
);
$brr
['list'] =
$this
->db->get('goods')->result_array();
$this
->load->view('Home/list.html',
$brr
);
}
<?php
foreach
(
$type
as
$v
){?>
<li id=
"cat_1"
class
=
""
>
<h3><a href=
""
><?php
echo
$v
['cat_name']?></a></h3>
<?php
foreach
(
$v
['child']
as
$vv
){?>
<dl
class
=
"clearfix"
>
<dt><a href=
""
><?php
echo
$vv
['cat_name']?></a></dt>
<?php
foreach
(
$vv
['childs']
as
$vvv
){?>
<a href=
""
><?php
echo
$vvv
['cat_name']?></a>
<?php }?>
</dl>
<?php }?>
</li>
<?php }?>