I am working on a page much like the ebay page where you choose a category for the item you want to sell. For those of you not familiar with it it goes like this. I have six select boxes. At each box, I have an add and delete button. The first box is the root categories and the other five are subcategories. When I click on one of the root categories, javascript populates the next box with another list, when I choose a subcategory in box 2 it populates box 3 and so on. I made it so you can add categories to the root categories and subcategories. All of the categories and subcategories are located in one table as follows:
|auto_count | category_name | ParentID |
| 1 | Root Category | 0 |
| 2 | Root Category2 | 0 |
| 3 | SubCat 1 | 1 |
| 4 | SubCat 2 | 3 |
| 5 | SubCat 3 | 1 |
So basically, I load all of the values into a javascript array. All of the entries with a parentID of 0 end up in the first box. If I were to click on "Root Category" in the first box, "SubCat1" and "SubCat3" would show up in the second box. If I click on "SubCat 1", "SubCat 2" shows up in the third. You get the picture. All of this works great.
The question I have is this. Is there some type of mysql query that I could run so that if I chose to delete "Root Category", that it would also delete any children associated with it?
In my example that would be if I were to delete "Root Category", It would delete "SubCat 1", "SubCat 2", and "SubCat 3". The whole tree essentially.
I am looking for the most dynamic answer. I don't want to do the same thing for each category box. I am looking for an answer that would include room for expansion(say if I wanted to add 4 more boxes) without having to change this code.
I am sorry for the real lengthy explanation. Thanks for any help guys.