AoN
Internet Programmer
- Aug 1, 2012
- 114
Ugh, I hate these brain farts. Long story short, I'm working on a customized, made-from-scratch, CMS to replace one of the websites currently used by the university I work for. For the sake of also catching up with the times, I'm working entirely in PDO, rather than just touching base here and there.
The PDO, I think, is not my problem, considering I have the menu array built from the database. Instead, I'm just having a lapse in intelligence in regards to how I can recursively format the array based upon what level of the array the information appears. Not sure why it is, but I'm just not getting any ideas on how to do this (I might've burnt myself out with the made-from-scratch session_handler() that adaptively uses cookies or $_GET with database validation. :S). So, I turn here! I'll give myself a break from the project for a few hours/days and see if I can think clearly afterwards, but I figure I can go ahead and ask anyways.
Here's the structure of the generated array:
Here's how I need it to be formatted:
For each additional level, ┃ would be added before ┣.
I'm running into two main issues. First, and the more annoying to me, I just can't seem to figure out how-to apply formatting based upon the level within the array. I'll be kicking myself for this for weeks after it's done. Secondly, and a little more based upon the first one since it's identification of array level, is retrieving the length of that array.
Basically, it should produce a table like:
It angers me to think that this should be easy for me, but I can't change what it is. ^^'
Thank you all, ahead of time, for taking a look. ^^
The PDO, I think, is not my problem, considering I have the menu array built from the database. Instead, I'm just having a lapse in intelligence in regards to how I can recursively format the array based upon what level of the array the information appears. Not sure why it is, but I'm just not getting any ideas on how to do this (I might've burnt myself out with the made-from-scratch session_handler() that adaptively uses cookies or $_GET with database validation. :S). So, I turn here! I'll give myself a break from the project for a few hours/days and see if I can think clearly afterwards, but I figure I can go ahead and ask anyways.
Here's the structure of the generated array:
Code:
Array
(
[1] => Array
(
[id] => 1
[pid] => 0
[name] => Home
[position] => 1
[hidden] => 0
[submenu] => Array
(
)
)
[2] => Array
(
[id] => 2
[pid] => 0
[name] => Student Resources
[position] => 2
[hidden] => 0
[submenu] => Array
(
[8] => Array
(
[id] => 8
[pid] => 2
[name] => Online Library
[position] => 1
[hidden] => 0
[submenu] => Array
(
)
)
[9] => Array
(
[id] => 9
[pid] => 2
[name] => Student Services
[position] => 2
[hidden] => 0
[submenu] => Array
(
)
)
[10] => Array
(
[id] => 10
[pid] => 2
[name] => MS Software
[position] => 3
[hidden] => 0
[submenu] => Array
(
)
)
[11] => Array
(
[id] => 11
[pid] => 2
[name] => Term Calendar
[position] => 4
[hidden] => 0
[submenu] => Array
(
)
)
[12] => Array
(
[id] => 12
[pid] => 2
[name] => Certification Tests
[position] => 5
[hidden] => 0
[submenu] => Array
(
)
)
)
)
[3] => Array
(
[id] => 3
[pid] => 0
[name] => Key Contacts
[position] => 3
[hidden] => 0
[submenu] => Array
(
[13] => Array
(
[id] => 13
[pid] => 3
[name] => Student Services
[position] => 1
[hidden] => 0
[submenu] => Array
(
)
)
[14] => Array
(
[id] => 14
[pid] => 3
[name] => Online Support
[position] => 2
[hidden] => 0
[submenu] => Array
(
)
)
[15] => Array
(
[id] => 15
[pid] => 3
[name] => Online Career Advisors
[position] => 3
[hidden] => 0
[submenu] => Array
(
)
)
[16] => Array
(
[id] => 16
[pid] => 3
[name] => Online Administrative Staff
[position] => 4
[hidden] => 0
[submenu] => Array
(
)
)
[17] => Array
(
[id] => 17
[pid] => 3
[name] => Online Financial Aid Representatives
[position] => 5
[hidden] => 0
[submenu] => Array
(
)
)
[18] => Array
(
[id] => 18
[pid] => 3
[name] => Online Admissions Representatives
[position] => 6
[hidden] => 0
[submenu] => Array
(
)
)
[19] => Array
(
[id] => 19
[pid] => 3
[name] => Program Directors
[position] => 7
[hidden] => 0
[submenu] => Array
(
)
)
)
)
[4] => Array
(
[id] => 4
[pid] => 0
[name] => Student Awards
[position] => 4
[hidden] => 0
[submenu] => Array
(
)
)
[5] => Array
(
[id] => 5
[pid] => 0
[name] => Tutorials
[position] => 5
[hidden] => 0
[submenu] => Array
(
[20] => Array
(
[id] => 20
[pid] => 5
[name] => Online Course Tutorial (WMV)
[position] => 1
[hidden] => 0
[submenu] => Array
(
)
)
[21] => Array
(
[id] => 21
[pid] => 5
[name] => Online Course Tutorial (SWF)
[position] => 2
[hidden] => 0
[submenu] => Array
(
)
)
[22] => Array
(
[id] => 22
[pid] => 5
[name] => CourseSmart eBook Tutorial
[position] => 3
[hidden] => 0
[submenu] => Array
(
)
)
[23] => Array
(
[id] => 23
[pid] => 5
[name] => Online Library Tutorial
[position] => 4
[hidden] => 0
[submenu] => Array
(
)
)
[24] => Array
(
[id] => 24
[pid] => 5
[name] => Entire Multimedia Library
[position] => 5
[hidden] => 0
[submenu] => Array
(
)
)
)
)
[6] => Array
(
[id] => 6
[pid] => 0
[name] => eBook
[position] => 6
[hidden] => 0
[submenu] => Array
(
[25] => Array
(
[id] => 25
[pid] => 6
[name] => CourseSmart eBook Tutorial
[position] => 1
[hidden] => 0
[submenu] => Array
(
[35] => Array
(
[id] => 35
[pid] => 25
[name] => Part 1
[position] => 1
[hidden] => 0
[submenu] => Array
(
)
)
[36] => Array
(
[id] => 36
[pid] => 25
[name] => Part 2
[position] => 2
[hidden] => 0
[submenu] => Array
(
)
)
)
)
[26] => Array
(
[id] => 26
[pid] => 6
[name] => CourseSmart eBook Portal
[position] => 2
[hidden] => 0
[submenu] => Array
(
[37] => Array
(
[id] => 37
[pid] => 26
[name] => Part 1
[position] => 1
[hidden] => 0
[submenu] => Array
(
)
)
[38] => Array
(
[id] => 38
[pid] => 26
[name] => Part 2
[position] => 2
[hidden] => 0
[submenu] => Array
(
)
)
)
)
[27] => Array
(
[id] => 27
[pid] => 6
[name] => Benefits of Using eBooks
[position] => 3
[hidden] => 0
[submenu] => Array
(
)
)
[28] => Array
(
[id] => 28
[pid] => 6
[name] => New Feature - Offline access
[position] => 4
[hidden] => 0
[submenu] => Array
(
)
)
[29] => Array
(
[id] => 29
[pid] => 6
[name] => Mozilla Firefox download
[position] => 5
[hidden] => 0
[submenu] => Array
(
)
)
)
)
[7] => Array
(
[id] => 7
[pid] => 0
[name] => Help
[position] => 7
[hidden] => 0
[submenu] => Array
(
[30] => Array
(
[id] => 30
[pid] => 7
[name] => Computer Requirements
[position] => 1
[hidden] => 0
[submenu] => Array
(
)
)
[31] => Array
(
[id] => 31
[pid] => 7
[name] => Survival Guide
[position] => 2
[hidden] => 0
[submenu] => Array
(
)
)
[32] => Array
(
[id] => 32
[pid] => 7
[name] => How to Access Your Student E-Mail
[position] => 3
[hidden] => 0
[submenu] => Array
(
)
)
[33] => Array
(
[id] => 33
[pid] => 7
[name] => 24/7 Technical Support
[position] => 4
[hidden] => 0
[submenu] => Array
(
)
)
[34] => Array
(
[id] => 34
[pid] => 7
[name] => Student Resource Services
[position] => 5
[hidden] => 0
[submenu] => Array
(
)
)
)
)
)
Here's how I need it to be formatted:
Code:
$page .= '
<tr>
<td colspan="2">┣{NAME}</td>
<td><input type="number" min="1" max="{LENGTH OF LEVEL OF ARRAY}" value="{POSITION}" /></td>
<td><input type="checkbox"';
if({HIDDEN} == 1) {
$page .= ' checked="checked"';
}
$page .= ' /></td>
<td><a href="?r=nav&o=rem&id={ID}">Remove?</a></td>
</tr>';
For each additional level, ┃ would be added before ┣.
I'm running into two main issues. First, and the more annoying to me, I just can't seem to figure out how-to apply formatting based upon the level within the array. I'll be kicking myself for this for weeks after it's done. Secondly, and a little more based upon the first one since it's identification of array level, is retrieving the length of that array.
Basically, it should produce a table like:
Code:
┣Home 7 1 0 1
┣Student Resources 7 2 0 1
┃┣Online Library 5 1 0 1
┃┣Student Services 5 2 0 1
┃┣MS Software 5 3 0 1
┃┣Term Calendar 5 4 0 1
┃┣Certification Tests 5 5 0 1
┣Key Contacts 7 3 0 1
┃┣Student Services 7 1 0 1
┃┣Online Support 7 2 0 1
┃┣Online Career Advisors 7 3 0 1
┃┣Online Administrative Staff 7 4 0 1
┃┣Online Financial Aid Representatives 7 5 0 1
┃┣Online Admissions Representatives 7 6 0 1
┃┣Program Directors 7 7 0 1
┣Student Awards 7 4 0 1
┣Tutorials 7 5 0 1
┃┣Online Course Tutorial (WMV) 5 1 0 1
┃┣Online Course Tutorial (SWF) 5 2 0 1
┃┣CourseSmart eBook Tutorial 5 3 0 1
┃┣Online Library Tutorial 5 4 0 1
┃┣Entire Multimedia Library 5 5 0 1
┣eBook 7 6 0 1
┃┣CourseSmart eBook Tutorial 5 1 0 1
┃┃┣Part 1 2 1 0 1
┃┃┣Part 2 2 2 0 1
┃┣CourseSmart eBook Portal 5 2 0 1
┃┃┣Part 1 2 1 0 1
┃┃┣Part 2 2 2 0 1
┃┣Benefits of Using eBooks 5 3 0 1
┃┣New Feature - Offline access 5 4 0 1
┃┣Mozilla Firefox download 5 5 0 1
┣Help 7 7 0 1
┃┣Computer Requirements 5 1 0 1
┃┣Survival Guide 5 2 0 1
┃┣How to Access Your Student E-Mail 5 3 0 1
┃┣24/7 Technical Support 5 4 0 1
┃┣Student Resource Services 5 5 0 1
It angers me to think that this should be easy for me, but I can't change what it is. ^^'
Thank you all, ahead of time, for taking a look. ^^