Unlimited classification
The infinite classification table associated with the parent ID, if you want to delete one of them, how to delete all its descendants?
Previous moderators have written not recursive tree arrays, so here to see if there is no recursive method to find out all the descendants of the element can be used to delete
Reply to discussion (solution)
Without recursion, I won't. I hope the answers are given by the Daniel Downstairs.
In particular, I would like to ask a question: "Is there a need for real-world applications?" The project manager won't let you use recursion? ”
Not to solve the problem for the purpose of the trouble is bullying ... Ha ha...
Without recursion, I won't. I hope the answers are given by the Daniel Downstairs.
In particular, I would like to ask a question: "Is there a need for real-world applications?" The project manager won't let you use recursion? ”
Not to solve the problem for the purpose of the trouble is bullying ... Ha ha...
Of course there is no forced regulation, just to find out that there are other ways to achieve the purpose. It's like I didn't see it. Before the implementation process of the moderator, the construction of the tree array has always been thought to be recursive
Find Orphans
Select ID from table where PID not in (select ID from table)
Delete the corresponding record after
Need to be done in a loop, because each time a deletion is possible new orphans are created
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 ());
Find Orphans
Select ID from table where PID not in (select ID from table)
Delete the corresponding record after
Need to be done in a loop, because each time a deletion is possible new orphans are created
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 ());
This is also a way of thinking, but this is also done several times the query and delete operations, and there are sub-queries.
Left and right values + upper and lower values are not recursive son to find dad up and down the value of the ancestors to find the following values