Home > php教程 > php手册 > 无限分类php 递归函数

无限分类php 递归函数

WBOY
Release: 2016-06-13 10:08:00
Original
994 people have browsed it

这款无限分类php 递归函数是一款php 与sql查询递归的方法,很简单就是查询一次当前分类没有没子类,如果有的话就再调用函数本身来操作,如果己经没有子类了就可以返回了。

这款无限分类php教程 递归函数是一款php 与sql查询递归的方法,很简单就是查询一次当前分类没有没子类,如果有的话就再调用函数本身来操作,如果己经没有子类了就可以返回了。

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 .= ' if ($row['sort_id'] == $selected)
{
$options .=' selected ';
}
$options .=">".str_repeat(' ',$n*3).$row['sort_name']."n";
$options .=createsortoptions ($selected,$row['sort_id'],$n);
}
}
return $options;
}

如果是用smarty模板的朋友可以如下调用

//– $tpl->assign('sort_list',createsortoptions ());
//– $tpl->assign('sort_list',createsortoptions ($sort_id));

 

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template