Home  >  Article  >  Backend Development  >  Infinite level selectTree class written in php

Infinite level selectTree class written in php

WBOY
WBOYOriginal
2016-07-25 09:03:241010browse
  1. /*

  2. author: nick
  3. Function: Generate SeletTree
  4. Attribute:
  5. $result result set
  6. $id_field own id field
  7. $parent_field parent class id field
  8. $option_text Option display name
  9. $select_name The name of the drop-down menu
  10. $elected Default selected
  11. $no_top Whether top-level options are required
  12. $level layer depth
  13. $parent_id id in the same layer
  14. */
  15. class SelectTree{
  16. public $result;
  17. public $ select_name;
  18. public $option_text;
  19. public $elected;
  20. public $id_field;
  21. public $parent_field;
  22. public $no_top;
  23. public $level;
  24. public $parent_id;
  25. public $getarray;
  26. function __construct($result,$ id_field,$parent_field,$option_text,$select_name='',$elected=0,$no_top=0,$level=0,$parent_id=0){
  27. $this->result =$result;
  28. $this- >id_field =$id_field;
  29. $this->parent_field =$parent_field;
  30. $this->option_text =$option_text;
  31. $this->select_name =$select_name;
  32. $this->elected =$elected ;
  33. $this->no_top =$no_top;
  34. $this->level =$level;
  35. $this->parent_id =$parent_id;
  36. $this->getarray =self::getArray();
  37. }

  38. /*

  39. Function: Return Tree two-dimensional array
  40. */
  41. function getArray(){
  42. $arrays=array();
  43. while($row=mysql_fetch_array($this-> ;result)){
  44. $arrays[$row[$this->parent_field]][$row[$this->id_field]]=$row;
  45. }
  46. return $arrays;
  47. }

  48. /*

  49. Function: Get SelectTree
  50. */
  51. function getSelectTree(){
  52. $tree = '


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