Skip to content Skip to sidebar Skip to footer

How Render A Tree In Html + Php(codeIgniter)

I have an adjacency model list and this is the query: SELECT t1.FIO AS lev1, t2.FIO AS lev2, t3.FIO AS lev3, t4.FIO AS lev4, t5.FIO AS lev5, t6.FIO AS lev6, t7.FIO AS lev7, t8.FIO

Solution 1:

Seems a bit complicated and inflexible what you're doing here Gilles. Would it not be better to create your database table with each row having its own category_id and a parent_id? ie give the top level parents a parent_id of 0 and the children take the parent_id of their parent's category_id. This would give you unlimited depth and will be easier to code when you're rendering the tree. For example:

SQL for your first level of hierarchy -

SELECT * FROM (your_table) WHERE parent_id=0

SQL for your second level of hierarcy -

SELECT * FROM (your_table) WHERE parent_id=(category_id of first level)

SQL for your third level of hierarcy -

SELECT * FROM (your_table) WHERE parent_id=(category_id of second level)

and so on...


Post a Comment for "How Render A Tree In Html + Php(codeIgniter)"