Jump to content

Auto Nested Categories from Flat File


natasha_thomas

Recommended Posts

Folks,

 

I have a flat file or CSV, which has the tree structure of the Nesed Categories (All are delimited by either > or tab, it can be set easily).

 

I want a PHP/Mysql code/routine that i can automaticaly create a table in MYsql with Parent Child relationship.

 

Logic is there in my mind, every distinct Node will be an ID which while every child node will have the PID (parent ID) of its Parent.

 

 

So the below data from flat file (Actual Data can be N Level Deep at least 4 Level):

 

 

Electronics
Electronics > Phones 
Electronics > Phones > Iphone
Electronics > Phones > LG
Electronics > Phones > Samsung
Electronics > Phones > Samsung > 3G


Electronics > Laptops
Electronics > Laptops > Dell
Electronics > Laptops > Sony
Electronics > Laptops > HP
Electronics > Laptops > HP > Core 2 Duo

 

 

 

Will look like this in Mysql Table Structure:

 

 

 

This is the Logic i need ot adopt, but i have no clue on how to code it to extract in this table structure and define this paren tchild mapping automatically.

 

Can someone Help me out wiht this?

 

 

 

Cheers

Natasha T

 

 

Link to comment
https://forums.phpfreaks.com/topic/228469-auto-nested-categories-from-flat-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.