Jump to content

[SOLVED] Need to sort a list of Ul's after it has been returned by a php script from db


walshd

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.