龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

无限分级算法

时间:2014-07-22 14:51来源: 作者: 点击:
分享到:
<无详细内容>
<?php
//无限分级分类
//来源: htttp://aiyooyoo.com

header('Content-type:text/html; charset=UTF-8');

$conn = mysql_connect('localhost', 'root', '123456');
mysql_select_db('xsphp');
mysql_query('SET NAMES utf8');

$result = mysql_query('SELECT id,fid,name FROM cat ORDER BY id');

$rows = array();
while ($row = mysql_fetch_assoc($result)) {
    $rows[$row['id']] = $row;
}

$t = array();
foreach ($rows as $id => $item) {
    if ($item['fid']) {
        $rows[$item['fid']][$item['id']] = &$rows[$item['id']];
        $t[] = $id;
    }
}

foreach($t as $u) {
    unset($rows[$u]);
}

print_r($rows);
精彩图集

赞助商链接