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 Link to comment https://forums.phpfreaks.com/topic/164495-solved-need-to-sort-a-list-of-uls-after-it-has-been-returned-by-a-php-script-from-db/ 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' Link to comment https://forums.phpfreaks.com/topic/164495-solved-need-to-sort-a-list-of-uls-after-it-has-been-returned-by-a-php-script-from-db/#findComment-867696 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 Link to comment https://forums.phpfreaks.com/topic/164495-solved-need-to-sort-a-list-of-uls-after-it-has-been-returned-by-a-php-script-from-db/#findComment-867718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.