php - How to create Hierarchical Links for Sitemap.html -


I need to create an HTML Sitemap similar to Apple.com/sitemap with the original category and sub class. I Two tables are created as follows: Primary category:

ID | TITLE | Url

as sub class:

ID | Parent_Category_ID | TITLE | URL ...

How do I recover it so that it resembles something:

Parent_Category

  • SubCata
  • Subcuta

    Edit: Following is a few online suggestions, so now there is a table:

      The original name of the ID URL 0 0 Painter 1 URL 1 2 0 Parent 2 Url 2 3 1 All 1 URL 3 4 0 Painter 3 URL 4 5 2 All 2 URL 5   

    Here is the code I used to use with a range of categories with sub categories In creating array I am

      & lt ;? Include php ('config.php'); Echo '& lt; Pre & gt; '; $ Categories = Sitemap :: getTopCategories (); Print_r ($ ranges); Echo & lt; / Pre & gt; '; Class sitemap {public static work getTopCategories () {returns self :: getCategories ('parent = 0'); } Public stable work getCategories ($ where = '') {if ($ where) $ where = "where $ $"; $ Result = mysql_query ("SELECT * FROM test $ where"); $ Ranges = array (); While ($ range = mysql_fetch_array ($ result)) {$ my_id = $ class ['id']; $ Category ['children'] = Sitemap :: getCategories ("parent = $ my_id"); $ Ranges [] = $ range; } Mysql_free_result ($ result); Return of $ categories; }}? & Gt;   

    Now what I want to follow, it displays it in a proper manner as apple.com/sitemap. I am ready with CSS for proper placement but I can not show it.

    Please help!

    Here is a function that I used to get in the array in a proper format.

      function output categories ($ categories, $ beginning = 0) {foreach ($ categories key as dollar = key = & gt; $ range) {if (count ($ category ['children']) gt; 0) {echo '& lt; Li & gt; & Lt; A title = "'. $ Range [' name '].' 'Href ="' $ range. ['Url']. ' '& Gt;' $ Range ['name']. '& Lt; / A & gt; & Lt; Ul & gt; '; Output ranges ($ range ['children'], starting level + 1); Echo "& lt; / li & gt;"; } Else {echo '& lt; Li & gt; & Lt; A title = "'. $ Range [' name '].' 'Href =' '. $ Range [' url ']." & Gt; '$ [' Name '].' & Lt; / A & gt; & Lt; / Li & gt; '; }} Echo "& lt; / ul & gt;"; Self return; }   

    Refer to this post for more information:

Comments