Answer the question
In order to leave comments, you need to log in
Recursive tree output from two tables?
Hello! Members of the forum, I have a question. I have 2 tables, in one (id, title), in the second (id, catalog_id, title). The second one refers to the ids of the first one with the catalog_id field, everything is clear here. The task is to display data from these tables in the form of a tree with checkmarks. Well, or ul-li, it doesn't matter here. Help me to understand?
select
*
from catalog c
join catalog_items ci on ci.catalog_id = c.id
Answer the question
In order to leave comments, you need to log in
<ul>
<?php
foreach($data as $one){
echo '<li>'.$one[title];
if(isset($one[items]) and is_array($one[items])){
foreach($one[items] as $second_level){
echo '<li>';
echo $second_level[title];
echo '</li>';
}
}
echo '</li>';
}
?>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question