Home >Backend Development >PHP Tutorial >Infinite-level classification implemented by php and mysql | tree display classification relationship

Infinite-level classification implemented by php and mysql | tree display classification relationship

WBOY
WBOYOriginal
2016-07-25 09:03:27774browse
  1. //$count is the classification level
  2. sort_list($str,$fatherid,$count)
  3. {
  4. $rs = $this->sql->re_datas("select * from sort where father_id = fatherid");
  5. $num = $this->sql->sql_numrows();
  6. $i=0;
  7. $n = 1;
  8. while(isset($rs[$i]))
  9. {
  10. $name = "";
  11. for($n = 1 ; $n < $count ; $n++)
  12. {
  13. $name.="│ ";
  14. }
  15. if($i+1==$ num)
  16. {
  17. $name.="└─".$rs[$i][name];
  18. }
  19. else
  20. {
  21. $name.="├─".$rs[$i][name];
  22. }
  23. if($rs[$i][isdir])
  24. {
  25. $str.="".$name."";
  26. }
  27. else
  28. {
  29. $str.=$name";
  30. }
  31. $temp = $count+1;
  32. $str = $this->sort_list($str,$rs[$i][id],$ temp);
  33. $i++;
  34. }
  35. return $str;
  36. }
  37. ?>
Copy code

where $this->sql object is a sql operation class object, and the re_datas() function returns the found Array, sql_numrows() function returns the queried number Calling method: $sort_list = sort_list($sort_list,0,1);



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