walshd Posted July 2, 2009 Share Posted July 2, 2009 OK I have a navigation system which is being dynamically generated from a db. this is all fine but I want the navigation to now be sorted alphabetically. My knowledge of PHP is limited and so all my own attempts have failed. Can someone please help me out here. the script I have so far is: <?php if(@$_SESSION["clientLoginLevel"] != "") $minloglevel=$_SESSION["clientLoginLevel"]; else $minloglevel=0; $result = mysql_query( "SELECT sectionID, sectionName, topSection, rootSection, sectionOrder, sectionDisabled FROM sections WHERE sectionDisabled<=" . $minloglevel . " ORDER BY sectionOrder" ); // prepare special array with parent-child relations $menuData = array( 'items' => array(), 'parents' => array() ); while ($menuItem = mysql_fetch_assoc($result)) { $menuData['items'][$menuItem['sectionID']] = $menuItem; $menuData['parents'][$menuItem['topSection']][] = $menuItem['sectionID']; } function buildMenu($parentId, $menuData, $dept) { if (isset($menuData['parents'][$parentId])) { echo '<ul id="catNav">'; foreach ($menuData['parents'][$parentId] as $itemId) { echo '<li><a href="products.php?cat=' . $menuData['items'][$itemId]['sectionName'] . '">' . $menuData['items'][$itemId]['sectionName']; if($dept>1) { echo buildMenu($itemId, $menuData, $dept-1); } echo '</a></li>'; } echo '</ul>'; } } // output the menu echo buildMenu(0, $menuData, 5); ?> any help advice or a solution would be greatly received. Dave Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2009 Share Posted July 2, 2009 Id suggest you change 'ORDER BY sectionOrder' to ORDER BY 'sectionName' Quote Link to comment Share on other sites More sharing options...
walshd Posted July 2, 2009 Author Share Posted July 2, 2009 ahh thanks.. could not see the woods for the trees. was a too caught up in trying to sort the output... Many thanks 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.