S
S
Sergey Valitov2015-10-17 13:34:50
PHP
Sergey Valitov, 2015-10-17 13:34:50

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

I collected everything in a heap, but I can’t figure out what to do with it .. somehow I need to push it into an array ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2015-10-17
@webinar

<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>

The answer to your question. If it doesn't fit, please clarify.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question