fallenboy Posted October 11, 2009 Share Posted October 11, 2009 Hi guys. I have a problem and i cant solve it b myself. Im pretty sure it has an easy solution but I just can't figure it out... This code outputs nested unordered list, but I need it to output array, multi level: function do_menu($parent, $menu) { $result = do_mysql("SELECT id, title FROM pages WHERE parent='{$parent}' ORDER BY id"); if(mysql_affected_rows() != 0) { $menu .= "<ul>\n"; while ($row = mysql_fetch_array($result)) { $menu .= "<li><a href=\"".ADMINURL."menu/index.php?section=open&id=".$row['id']."\">".stripslashes(htmlspecialchars_decode($row['title']))."</a>"; $menu = do_menu($row['id'], $menu); $menu .= "</li>\n"; } $menu .= "</ul>\n"; } else $menu = false; return $menu; } Can somebody help me, please? Thanks guys PS! If this function sucks, it's OK as I'm not very good programmer, more HTML-guy Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 11, 2009 Share Posted October 11, 2009 can you tell us what problem you're having with the function you posted? I can see a few things like not doing $menu .= on the recursive call, but there may be deeper issues I'm not seeing. Quote Link to comment Share on other sites More sharing options...
fallenboy Posted October 11, 2009 Author Share Posted October 11, 2009 can you tell us what problem you're having with the function you posted? I can see a few things like not doing $menu .= on the recursive call, but there may be deeper issues I'm not seeing. The function works fine, but it outputs HTML. I want it to output multilevel array: now. <ul> <li>menu 1 <ul> <li>menu 1 1</li> <li>menu 1 2</li> </ul> </li> <ul> but i want it to output multievel PHP array. array ->menu[1] -> array(id => 2, parent =>1), array(id =>3, parent => 1) I just cant make it work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.