mysql - How to build a tree in php having id, parent_id and depth variables -


is the ID from mysql query, parent_id and depth variable

depth starts with 0

Can you give me an elegant solution or a good link

I am using CI

First of all, you should read all the child elements and" To output as a recursive function must be typed.

Once you get the right size, you can use the following example code to correct the diagram.

or

You can also do the code below

  function print_list ($ array , $ Parent = 0) {print "& lt; ul & gt;"; Forex currency ($ line as $ line) {if ($ row-> gt; parent_id == $ parent) {Print "
  • Title =" $ row-> "; Print_list ($ array, $ line-> ID); #Rickers Print "& lt; / li & gt;"; }} Print "& lt; / ul & gt;"; }

    print_list is a recursive function and $ array has all the rows from the database.



  • Comments