当前位置: 移动技术网 > IT编程>开发语言>PHP > php用数组返回无限分类的列表数据的代码

php用数组返回无限分类的列表数据的代码

2019年04月27日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

/*—————————————————— */
//– 获取无限分类的列表数据
/*—————————————————— */
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;
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网