I have a nested drag and drop list which return json formattet string. I can run php serialize, json_decode, etc. on this string. But I stuck at saving the hierarchy in DB.
Example of returned output:
[{“id”:1,”children”:[{“id”:2,”children”:[{“id”:4},{“id”:7},{“id”:8}]},{“id”:3}]},{“id”:5},{“id”:6}]
…or…
Array
(
[0] => Array
(
[id] => 1
[children] => Array
(
[0] => Array
(
[id] => 2
[children] => Array
(
[0] => Array
(
[id] => 4
)
[1] => Array
(
[id] => 7
)
[2] => Array
(
[id] => 8
)
)
)
[1] => Array
(
[id] => 3
)
)
)
[1] => Array
(
[id] => 5
)
[2] => Array
(
[id] => 6
)
)
I want to save this output to a DB-structure like this:
CREATE TABLE IF NOT EXISTS `menu` ( `id` int(11) NOT NULL AUTO_INCREMENT, `rang` int(11) NOT NULL, `parent_id` int(11) NOT NULL, `name` varchar(256) NOT NULL, `description` varchar(256) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
Any ideas?
I would do it this way:
You should get array like this: