[prev in list] [next in list] [prev in thread] [next in thread]
List: php-general
Subject: Re: [PHP] Recursion with database tables
From: David Otton <phpmail () jawbone ! freeserve ! co ! uk>
Date: 2003-02-19 13:42:42
[Download RAW message or body]
On Wed, 19 Feb 2003 14:16:47 +0000, you wrote:
>>Otherwise, yes, in MySQL you have to recurse down the tree deleting
>>comments.
>How would I go about recursing down the tree? Has anyone done this before?
I have, but it's been a while. Something like (pseudo-code) .
def delete_comments(a) :
for b in a :
c = "SELECT commentid FROM comments WHERE parentcommentid = a"
if len(c) > 0 :
delete_comments(c)
"DELETE FROM comments WHERE commentid IN (a)"
return
def main() :
a = "SELECT commentid FROM comments WHERE topicid = 1234"
delete_comments(a)
"DELETE FROM topic WHERE topicid = 1234"
where a is a list of commentids, b is a single commentid and c is a list
of child commentids. This will delete the tree in a depth-first fashion.
This is quite an intensive way of doing things (potentially many selects
and deletes) but is just-about acceptable because you probably will
delete an entire topic so infrequently.
I recommend filling out the topicid on every post as the easier
solution, though.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic