<p >thinkphp 做的一个无限循环分类</p>
<p >function getChild($id,$lv=2,$select='')<br />
{<br />
$dao=M('Fenlei');<br />
$sql=$id==0 ? "select * from fenlei where c_id=0" : "select * from fenlei where c_id='$id'";<br />
$result=mysql_query($sql);<br />
$str=$id==0 ? '<option value="0" selected>顶级分类</option>' : '';<br />
if(mysql_num_rows($result)>0)<br />
{<span class="Apple-converted-space"></span><br />
$space='';<br />
for($i=0;$i<$lv;$i++)<br />
{<br />
$space.='&nbsp;&nbsp; ';<br />
}<span class="Apple-converted-space"></span><br />
$lv+=1;<span class="Apple-converted-space"></span><br />
while($row=mysql_fetch_array($result)){<br />
$selected=$row['id']==$select ? 'selected' : '';<br />
$str.=' <option value="'.$row['id'].'"'.' '.$selected.'>'.$space.'→'.$row['name'].'</option>';<span class="Apple-converted-space"></span><br />
$str.=$this->getChild($row['id'],$lv);<br />
}<br />
}<br />
return $str;<br />
}</p>