Home >php教程 >php手册 >php递归实现无限分类生成下拉列表的函数

php递归实现无限分类生成下拉列表的函数

WBOY
WBOYOriginal
2016-06-06 20:34:511096browse

php自定义函数之递归实现无限分类生成下拉列表,这样可以提高效率,不用每次都从数据库读取数据。

复制代码 代码如下:


/*—————————————————— */
//– 递归实现无限分类生成下拉列表函数
//– $tpl->assign('sort_list',createSortOptions ());
//– $tpl->assign('sort_list',createSortOptions ($sort_id));
/*—————————————————— */
function createSortOptions ($selected=0,$parent_id=0,$n=-1)
{
global $db;
$sql = "SELECT * FROM `@__article_sort` WHERE `parent_id` = '{$parent_id}'";
$options = ";
static $i = 0;
if ($i == 0)
{
$options .= '\n";
$options .=createSortOptions ($selected,$row['sort_id'],$n);
}
}
return $options;
}

,虚拟主机,网站空间,香港服务器
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