When I refer to nested set model I mean what is described here.
I need to build a new system for storing \"categories\" (I can\'t think of better word for it) in a user
You can sort thier when you render. I explained rendering here How to render all records from a nested set into a real html tree
See my simple solution from method of my class. $this->table->order is Nette framework code to get data from DB.
$tree = Array();
$parents = Array();
$nodes = $this->table->order('depth ASC, parent_id ASC, name ASC');
$i = 0;
$depth = 0;
$parent_id = 0;
foreach($nodes as $node) {
if($depth < $node->depth || $parent_id < $node->parent_id) {
$i = $parents["{$node->parent_id}"] + 1;
}
$tree[$i] = $node;
$parents["{$node->id}"] = $i;
$depth = $node->depth;
$parent_id = $node->parent_id;
$i += (($node->rgt - $node->lft - 1) / 2) + 1;
}
ksort($tree);