The delete operation of an unlimited category uses an infinite category table associated with the parent ID. if you want to delete a temporary table, how can you delete all its descendants? Previously, the moderator wrote & nbsp; that is, there is no need to recursively construct a tree array, so here we can see whether there is a non-recursive method to find out all descendant elements that can be used to delete infinite categories of delete operations.
If you want to delete an infinite classification table associated with a parent ID, how can you delete all its descendants?
Previously, the moderator wrote that tree arrays are not recursively constructed, so here we can see whether there are any recursive methods that can be used to find all descendant elements that can be used to delete unlimited categories. share:
------ Solution --------------------
If you don't need recursion, I won't solve this problem. I hope the experts below will give answers.
In particular, I would like to ask a question: "Is there such a requirement in actual applications? The project manager won't let you use recursion ?"
Self-seeking troubles that do not aim to solve the problem are all hooligans... Haha...
------ Solution --------------------
Find orphan
SELECT id FROM table where pid not in (select id from table)
And then delete the corresponding record
It needs to be carried out in a loop, because each deletion may result in a new orphan.
Roughly like this:
Do {
$ Rs = mysql_query ('select group_concat (id) FROM table where pid not in (SELECT id from table )');
List ($ g) = mysql_fetch_row ($ rs );
Mysql_query ("delete from table where id in (g )");
} Where (mysql_affected_rows ());
------ Solution --------------------
The left and right values + the upper and lower values do not need recursion. the son finds the father and the upper and lower values. The ancestor finds the lower left and right values.