First of all thanks to stackoverflow to provide this plattform and you, to give a newbie a help ;-)
Now .. I have 2 tables: pages and sections Each has an own id. A page has one or more sections. A section belongs to exactly 1 page. The list sequence of both id's is handled in a different field.
I read both tables and create an (unsorted) array. What I finally need is a sorted list as shown below, having the page_id's and section_id's in the correct sequence..
Here an example of my tarray after retrieve data:
myArr[] = array( page_id=>2, section_id=>2, parent_id=>0, level=>0, page_seq=>1, section_seq=>2, page_title=>p1 );
myArr[] = array( page_id=>2, section_id=>9, parent_id=>0, level=>0, page_seq=>1, section_seq=>1, page_title=>p1 );
myArr[] = array( page_id=>3, section_id=>3, parent_id=>0, level=>0, page_seq=>2, section_seq=>1, page_title=>p2 );
myArr[] = array( page_id=>4, section_id=>4, parent_id=>0, level=>0, page_seq=>3, section_seq=>1, page_title=>p3 );
myArr[] = array( page_id=>5, section_id=>5, parent_id=>3, level=>1, page_seq=>3, section_seq=>1, page_title=>p2-3 );
myArr[] = array( page_id=>6, section_id=>6, parent_id=>3, level=>1, page_seq=>2, section_seq=>1, page_title=>p2-2 );
myArr[] = array( page_id=>7, section_id=>7, parent_id=>4, level=>1, page_seq=>1, section_seq=>1, page_title=>p3-1 );
myArr[] = array( page_id=>8, section_id=>8, parent_id=>7, level=>2, page_seq=>1, section_seq=>1, page_title=>p3-1-1 );
myArr[] = array( page_id=>9, section_id=>10, parent_id=>5, level=>2, page_seq=>1, section_seq=>1, page_title=>p2-1-1 );
myArr[] = array( page_id=>9, section_id=>11, parent_id=>5, level=>2, page_seq=>1, section_seq=>2, page_title=>p2-1-1 );
myArr[] = array( page_id=>10, section_id=>12, parent_id=>3, level=>1, page_seq=>1, section_seq=>1, page_title=>p2-1 );
My problem is the sorting.
- The section_seq is a sequence of the section within the page.
- The page_seq is a sequence of the page within the level for the same parent.
I find some rekursive loop examples already here, but - to be honest - I'm not able to adapt them to my needs. And, do I need a rekursive loop ?
What should be the key of my array: the section_id, because it is unique over all pages ? How to do the correct sort ?
Just to be noted: the page title could unfortunately not to be used - as in the example above - for sorting purposes ;-) as it is free text...
So what I need is:
- read first page (1) with level 0 and page_seq = 1
- read first page (2) having level 1 -if exists- with page (1) as parent and page_seq = 1
- read first page (3) having level 2 -if exists- with page (2) as parent and page_seq = 1
- ... continue as long as no more deeper level exists
- read second page (4) having level 2 -if exists- with page (2) as parent and page_seq = 1
- ... continue as long as no more deeper level exists and also no more pages on this level having page (2) as parent
- read second page (5) having level 1 -if exists- with page (1) as parent and page_seq = 1
- ... continue as long as no more deeper level exists and also no more pages on this level having page (5) as parent
- read second page (6) with level 0 and page_seq = 2
- and so on.
Any powerfull help & ideas ?
Thanks in advance Wolfgang