I have tree where user can drag and drop element and change elements positions.
After every change I’m sending this serialize array and I want to save it .
Example tree :
Economics
Blogging
General Dev
Japan
Productivity
Humanities
Education
Science
Haskell
Earth
PHP
I’m sending serialize tree throught ajax so I have array linke this.
'0' => "1"
'1' => "2"
'2' => "3"
'3' => "4"
'4' ...
'0' => "5"
'1' ...
'0' ...
'0' => "6"
'1' ...
'0' => "7"
'1' ...
'0' => "8"
'1' ...
'0' ...
'0' => "9"
'1' ...
'0' => "10"
'1' ...
'0' => "11"
Array value is table row id.
how insert this array into database with correct position ?
I would suggest using traditional tree storing approach:
So first of you need to fill up db properly, then rest should be easy to handle.
actual code.
Client side:
Server side (sort.php):
Notes and assumptions:
1) catalogue_id should be 0 for top level categories
2) I believe you are smart enough to get the client side dynamically rendered.
3) Assumes ord is 1 based.
4) php not tested, but should be ok