php - Recursive array correct method of display -


Sorry guys work again with my recursive array but I can not get a "layout", after which i do I & lt; Ul & gt; , & lt; Li & gt; "Proper" tree structure using the so that you finish it:

  • Item
    • Children
      • Child
        •   function recursive_array ($ result, $ Tbl) {global $ dBH}  

          ; $ Tbl = $ tbl; If (count ($ result)) {foreach ($ result in $ res) {if ($ res-> ParentID == 0) {echo ' "; Echo & lt; Li & gt; '; Resonance $ res-> Name; Echo $ res-> description; Resonance $ res-> Date_ added; Echo & lt; Ul & gt; '; } If ($ res-> ParentID! = 0) {echo '& lt; Li & gt; '; Resonance $ res-> Name; Echo $ res-> description; Resonance $ res-> Date_ added; Echo & lt; / Li & gt; '; } $ STH = $ DBH- & gt; Query ("SELECT * FROM". $ Tbl. "WHERE ParentID = '". $ Res-> ID. "'"); $ Fquerycount = $ STH- & gt; Punctiquity (); $ STH- & gt; SetFetchMode (PDO :: FETCH_OBJ); Recursive_array ($ STH, $ tbl); If ($ res-> ParentID == 0) {echo '& lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt; '; }}}}}

          I'm not really a fan of recursive SQL. Used, it works, but it always shouted me as ... ... consumed ...

          Instead of: Create a topic id (some kind of selector in which All items will include you ultimately want output) and select it based on it, ordered by the parent.

            SELECT * FROM $ tbl WHERE topicID = 1 by ORDER parent;   

          Then, you organize in such a way:

            $ output = array (); $ CurrentParent = -1; While receiving ($ line = $ stemat-> (PDO :: FETCH_OBJ)) {if ($ current modifier! = $ Line-> ParentID) {$ currentParent = $ row- & gt; ParentID; $ Output [current $ parent] = array (); } $ Output [$ currentParent] [] = $ line; } Function output list (array $ current, array $ output) {echo '& lt; Ul & gt; '; Forex currency (current $ as $ $) {echo ' Name; Echo $ res-> description; Resonance $ res-> Date_ added; // If this is set, then we explicitly have a node to node, if (isset ($ output [$ res-> ID])) function with // seed / node value The next call (found in the output) and it will make the appropriate ul and li tag outputLists ($ $ [$ res-> ID], $ output); Echo & lt; / Li & gt; '; } Echo '& lt; / Ul & gt; '; } // Start from the group with parentID = 0 output list ($ output [0], $ output);   

          Therefore, instead of recursive SQL, you have an output that is forming a tree-like structure in PHP.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -