php递归实现无限分类生成下拉列表的函数
代码如下:
/*―――――――――――――――――― */ //C 递归实现无限分类生成下拉列表函数 //C $tpl->assign('sort_list',createSortOptions ()); //C $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 .= '<option value="0″ >请选择</option>'; } $res = $db->query ($sql); if ($res) { $n++; while ($row = $db->fetch_assoc ($res)) { $i++; $options .="<option value='{$row['sort_id']}'"; if ($row['sort_id'] == $selected) { $options .=' selected '; } $options .=">".str_repeat(' ',$n*3).$row['sort_name']."</option>\n"; $options .=createSortOptions ($selected,$row['sort_id'],$n); } } return $options; }
相关推荐
Wonder的学习 2020-06-13
dushine00 2020-04-17
PM实验室 2020-03-08
wordmhg 2020-03-08
wenxuegeng 2020-01-26
xjd0 2019-11-27
ytp00ytp 2019-09-07
Purgatory00 2019-03-22
星月高悬 2011-06-27
风和日丽 2019-06-28
goodyatou 2016-03-27
dxbjfu0 2019-06-20
Kiritow的学园 2014-09-23
MrA 2018-07-05
cl00abc 2018-05-08
xiekch 2017-09-28
zyncool 2017-08-04
yxqfxd 2018-07-27