php - Recursive Function To Create Array -
I use KOHANA framework and I am trying to code the recursive function to create a class tree.
My Categories Table
id int (11) No PRI tap auto_increment name varchar (50) No tap parent_id int (11) No null projects_count int (11) No null
My example which is not working
public stable work category_list ($ parent_id = 0) {$ result = database :: example () - & Gt; Query ('SELECT name, projects_count FROM project_categories WHERE parent_id =?', Array ($ parent_id)); $ Project_categories = Array (); Forex Currency ($ result as $ line) {$ project_categories [] = $ line; Project_Categories_Model :: Factory () - & gt; Category_list ($ parent_id + 1); } Return $ project_categories; }
Using hierarchical data implementation is extremely non-optimal, because of receiving For each subcategory you should do a different query of the database. Here you want to create a recurring function.
If you still can change your table structure, please check it.
This article describes a solution, the entire hierarchy in a time query, therefore the recursive function will not be required.
Comments
Post a Comment