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 ; $ Tbl = $ tbl; If (count ($ result)) {foreach ($ result in $ res) {if ($ res-> ParentID == 0) {echo ' 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. Then, you organize in such a way: Therefore, instead of recursive SQL, you have an output that is forming a tree-like structure in PHP. & lt; Ul & gt; ,
& lt; Li & gt; "Proper" tree structure using the so that you finish it:
function recursive_array ($ result, $ Tbl) {global $ dBH}
SELECT * FROM $ tbl WHERE topicID = 1 by ORDER parent;
$ 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 '
Comments
Post a Comment