background image

将最顶层的类别的 fid 设置为 0
*/

function

 get_array(

$id

=0){

$sql

="select id,fid,cname from e_cat where fid= $id";

$result

=mysql_query(

$sql

);

$arr

=

array

();

if

(

$result

 && mysql_affected_rows()){

while

(

$rows

=mysql_fetch_assoc(

$result

)){

 

$rows

['child']=get_array(

$rows

['id']);

$arr

[] = 

$rows

;

}

return

 

$arr

;

}

echo

 '<pre>';

$result

 = get_array();

print_r(

$result

);

</PRE><BR>
<BR>
<P></P>
<P> </P>
<P>函数首先查询出所有 fid 为 0 的类</P>
<P>通过

while

逐个循环进行回调查找 fid 为当前类的 id 的子类</P>

<P><BR>
</P>
<P><BR>
</P>
<BR>
<BR>
<PRE></PRE>
</PRE>