I started a tree structure database from scratch, and I thought I had it right, heres what it looks like:

but there musta been a glitch in there somewhere because the categories aren't organised properly anymore. I don't know how to go about fixing this now. Also, I have other category tables which I'd like to convert into a heirarchical structure, but they are packed full of entries so building it up from scratch manually isn't an option. Its the lft and rgt part that would be too difficult for me to enter manually, I can put in parent ids though, and I know that I could make a script to organise the lft, rgt values based on the parent_id but don't wanna go reinventing the wheel here, is there a tool that'll do this automatically? How do you all deal with heirarchical databases? Is the left and right value approach the best way to do it?