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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.