Answer the question
In order to leave comments, you need to log in
How to make tree structure from categories database in CodeIgniter?
Good day. The question arose of how to make a tree-like structure of categories. The category data is taken from the database. Tried a bunch of code. But in all cases nothing is output.
Maybe there is some library or helper that will help to make this structure.
I think the code will come in handy!
function get_tree($parent_id = 0, $prefix = "") {
$CI = &get_instance();
global $out;
$query = "SELECT * FROM categories WHERE cat_id = '$parent_id'";
$result = $CI->db->query($query);
while ($row = $result->result_array) {
$out .= $prefix.$row['name']."<br>";
get_tree($row['cat_id'], $prefix." ");
}
return $out;
Answer the question
In order to leave comments, you need to log in
use for example nested sets - just a tree structure, I think you will find a lot of implementations in Google
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question