Sorting array by id and parent id

hi,

Im building a flash menu/section system for a cms. Im have a
little problem of sorting a array. The array get its rows from
a mysql db, im using PHPobject to get the sql records in flash.

MySql table has following colums; id, title, parent-id. When all
is stored in a flash array it look likes this;

row id, title, pid
[0] - 34,2005,0
[1] - 35,Nyheter,34
[2] - 36,Om Brasswind,34

And here comes my problem, when i attach movieclips i get linare
menu if you understand, but what i wont is a three-menu look at it,
like this;

2005 (id 34 pid 0)
|
± Nyheter (id 35 pid 34)
|
± Om Brasswind (id 36 pid 34)

Is possible to sort array this way? any advices…

her is my code used to get the ‘linare’ kind;


function viewSectionRecords(){
	for (var i=0; i<sectionRow.length; i++){		
		var item_obj = this.createEmptyMovieClip ("item_holder"+i, i);
		item_obj._x = 120; 
		item_obj._y = 145;
		var holder_obj = item_obj.attachMovie ("section_item_mc", "section_item_mc"+i, i)
		holder_obj._x = 0;
		holder_obj._y = 7 + ((holder_obj._height * i)+3);
		holder_obj.item_txt.text = sectionRow*[1];
	}
}