I need help to generate a tree of categories from a CSV file.
I tried many things, but I get lost …
I have a file of 800 lines that looks like this:
"LOADERS", "S130", "Above & 524611001, 524711001 & Above", "MAINTENANCE ITEMS", "SCHEDULED MAINTENANCE ITEMS (500 HOUR)"
"LOADERS", "S130", "Above & 524611001, 524711001 & Above", "MAINTENANCE ITEMS", "SCHEDULED MAINTENANCE ITEMS (1000 HOUR)"
"LOADERS", "S130", "Above & 524611001, 524711001 & Above", "MAIN FRAME", "OPERATOR CAB"
On those lines,
Column 1 represents the parent class
Column 2 is the child of Column 1
Column 3 is the child of Column 2
Column 3 is the mother of Column 4 (but it’s an explode (‘,’, Column 3))
Explode in column 4 are the mothers of 5
I would like to generate an array of this type (and created an ID starting at 50) because the goal is to convert this file into a mysql DB: s
I would succeed in having something like this
LOADERS (id = 50)
|___S130 (id = 51)
|----|____Above & 524611001 (id = 52)
|-----------|____ MAINTENANCE ITEMS (id = 53)
|------------------|____SCHEDULED MAINTENANCE ITEMS (500 HOUR) (id = 54)
|------------------|____SCHEDULED MAINTENANCE ITEMS (1000 HOUR) (id = 55)
|-----------|____ MAIN FRAME (id = 56)
|------------------|____OPERATOR CAB (id = 57)
|----|____Above & 524711001 (id = 58)
|-----------|____ MAINTENANCE ITEMS (id = 59)
|------------------|____SCHEDULED MAINTENANCE ITEMS (500 HOUR) (id = 60)
|------------------|____SCHEDULED MAINTENANCE ITEMS (1000 HOUR) (id = 61)
|-----------|____ MAIN FRAME (id = 62)
|------------------|____OPERATOR CAB (id = 63)
I tried a bunch of method and I begin to despair. Everything I did not even approaching the desired result: s I sweat on it since Monday and I want to hang myself.
Try something like this: