php用数组返回无限分类的列表数据的代码
(编辑:jimmy 日期: 2024/11/30 浏览:3 次 )
复制代码 代码如下:
/*—————————————————— */
//– 获取无限分类的列表数据
/*—————————————————— */
function get_sort ($parent_id=0,$n=-1)
{
global $db;
static $sort_list = array ();
$sql = "SELECT * FROM ".$db->table('article_sort')." WHERE `parent_id` = '{$parent_id}'";
$res = $db->query ($sql);
if ($res)
{
$n++;
while ($row = $db->fetch_assoc ($res))
{
$sql = "SELECT * FROM ".$db->table('article_sort')." WHERE `parent_id` = '{$row['sort_id']}'";
$children = $db->num_rows ($sql);
$row['sort_name'] = str_repeat (' ',$n*4).$row['sort_name'];
$row['children'] = $children;
$sort_list[] = $row;
get_sort ($row['sort_id'],$n);
}
}
return $sort_list;
}
/*—————————————————— */
//– 获取无限分类的列表数据
/*—————————————————— */
function get_sort ($parent_id=0,$n=-1)
{
global $db;
static $sort_list = array ();
$sql = "SELECT * FROM ".$db->table('article_sort')." WHERE `parent_id` = '{$parent_id}'";
$res = $db->query ($sql);
if ($res)
{
$n++;
while ($row = $db->fetch_assoc ($res))
{
$sql = "SELECT * FROM ".$db->table('article_sort')." WHERE `parent_id` = '{$row['sort_id']}'";
$children = $db->num_rows ($sql);
$row['sort_name'] = str_repeat (' ',$n*4).$row['sort_name'];
$row['children'] = $children;
$sort_list[] = $row;
get_sort ($row['sort_id'],$n);
}
}
return $sort_list;
}
下一篇:php自定义函数之递归删除文件及目录