I have two tables in my database - Category and Food. Food has idCategory. Category has id and idParentCategory.
From them, I need to create a string which will look like this (or xml):
<?xml version="1.0">
<tree id="0">
<item text="Category1">
<item text="Food1"/>
<item text="Food2"/>
</item>
<item text="Category2">
<item text="Category1">
<item text="Food3"/>
<item text="Food4"/>
</item>
<item text="Category3">
<item text="Food5"/>
<item text="Food6"/>
</item>
</item>
</tree>
How to create it? I tried finding the category which has id == 1, and then search all its children, but it's very complex. Is there an easy way?
One category can have many categories, but their children can have only food.