Home >Backend Development >PHP Tutorial >PHP recursively implements unlimited classification to generate drop-down list function code

PHP recursively implements unlimited classification to generate drop-down list function code

WBOY
WBOYOriginal
2016-07-25 08:54:10957browse
  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. }
复制代码

>>> 您可能感兴趣的文章: php mysql实现无限分类的实例代码 php无限分类的例子(仿淘宝商品分类) 提高php无限分类查询的效率(使用数组和递归) php实现的无限分类(递归版本)的例子 使用php数组实现的无限分类(不使用数据库与用递归) php写的一个递归实现无限分类生成下拉列表的函数



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