Home >Backend Development >PHP Tutorial >A function written in PHP to recursively implement unlimited classification and generate drop-down lists

A function written in PHP to recursively implement unlimited classification and generate drop-down lists

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:03:23968browse
  1. /*—————————————————— */
  2. //– 递归实现无限分类生成下拉列表函数
  3. //– $tpl->assign('sort_list',createSortOptions ());
  4. //– $tpl->assign('sort_list',createSortOptions ($sort_id));
  5. /*—————————————————— */
  6. function createSortOptions ($selected=0,$parent_id=0,$n=-1)
  7. {
  8. global $db;
  9. $sql = "SELECT * FROM `@__article_sort` WHERE `parent_id` = '{$parent_id}'";
  10. $options = ";
  11. static $i = 0;
  12. if ($i == 0)
  13. {
  14. $options .= '
  15. {
  16. $options .=' selected ';
  17. }
  18. $options .=">".str_repeat(' ',$n*3).$row['sort_name']."n";
  19. $options .=createSortOptions ($selected,$row['sort_id'],$n);
  20. }
  21. }
  22. return $options;
  23. }
  24. ?>
复制代码


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