show categories and subcategories tree from xml file in php
Posted: Thu Feb 12, 2015 8:16 am
Hi guyz
i want to show categories and subcategories like this
categoriery 1
-- subcategory
-- subcategory
categoriery 2
-- subcategory
-- subcategory
i got xml data like this
parent id is locating main category id hope u can understand this
and i'm using simplexml load file to for fetching information from xml file . with that code i able to fetch every category information but i want to show category first then under there show its subcategory
anyone who can help me
Any help would be greatly appreciated!
i want to show categories and subcategories like this
categoriery 1
-- subcategory
-- subcategory
categoriery 2
-- subcategory
-- subcategory
i got xml data like this
Code: Select all
<categories>
<category>
<categories_name> NAme 1</categories_name>
<categories_id>2</categories_id>
<parent_id>0</parent_id>
<sort_order>90</sort_order>
</category>
<category>
<categories_name>NAme 2</categories_name>
<categories_id>3</categories_id>
<parent_id>2</parent_id>
<sort_order>5</sort_order>
</category>
<category>
<categories_name>Name 3</categories_name>
<categories_id>4</categories_id>
<parent_id>0</parent_id>
<sort_order>20</sort_order>
</category>
<category>
<categories_name>Name 4</categories_name>
<categories_id>5</categories_id>
<parent_id>4</parent_id>
<sort_order>40</sort_order>
</category>
</categories>and i'm using simplexml load file to for fetching information from xml file . with that code i able to fetch every category information but i want to show category first then under there show its subcategory
Code: Select all
<?php
$xml=simplexml_load_file("cc.xml") or die("Error: Cannot create object");
foreach($xml->children() as $category) {
$catname = $category->categories_name;
$catid = $category->categories_id;
$parentid = $category->parent_id;
$sortorder = $category->sort_order;
echo " <div class='products'>
$catname | $catid | $parentid | $sortorder
</div> ";
} ?>Any help would be greatly appreciated!