Home  >  Article  >  Backend Development  >  PHP code to use array to return infinite categories of list data_PHP tutorial

PHP code to use array to return infinite categories of list data_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:35:05820browse

复制代码 代码如下:

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/322311.htmlTechArticle复制代码 代码如下: /*—————————————————— */ //– 获取无限分类的列表数据 /*——————————————————...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn