Important alert: (current site time 7/15/2013 10:32:00 PM EDT)
|
|
Message Board Recursive Thread Delete
|
Email
|
| Submitted on: |
7/14/2001 3:59:29 PM |
| By: |
Tim Feeley
|
| Level: |
Intermediate |
| User Rating: |
Unrated |
| Compatibility: |
ASP (Active Server Pages) |
| Views: |
10205 |
|
(About the author) |
|
|
|
A threaded message board system is fine and dandy, but eventually, someone will want to delete a post. And it would be awfully silly and wasteful to have several reply threads hanging out in your database sipping on Pina Coladas while everyone else is doing work. Using this code, you can cycle through all related threads to remove entries.
This article has accompanying files
|
| | Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
Recursive Thread Delete
Hello! Let's get started. I promise this tutorial won't be boring. You may
enjoy yourself! Also, let me stress that this probably isn't the most efficient
method in the entire world. Based on my debugging and testing, it seems to work
with minimal pain, but then again I only used 15 or so records to test.
Notes:
> I used a DSN called 'fspace', or "friendspace," for a message board I am
programming. Also, it's more of a journal-entry interface, so "CommentID" is
used as opposed to MessageID.
> This code hasn't been tested with massive message board systems, but if you
end up using it, please let me know how it fairs. :)
Let's begin by the data structure. I am using this:
CommentID ParentID Data
(subject, message, etc.)
The CommentID is the individual message ID, an AutoNumber.
The ParentID should be set to "0" for top level threads, and the
CommentID of a parent if it is a "reply"
Any additional data is not used, as we only need these two values
for deletion purposes.
This code will basically start with the top-level CommentID you wish to
delete. Let's use this table for example,
| CommentID |
ParentID |
Subject... |
| 1 |
0 |
Topic 1 |
| 2 |
0 |
Topic 2 |
| 3 |
2 |
Re: Topic 2 |
| 4 |
2 |
Re: Topic 2 |
| 5 |
3 |
Re: Re: Topic 2 |
| 6 |
5 |
Re: Re: Re: Topic 2 |
The code will take the CommentID we wish to delete, for example, "2".
It will remove 2 and then search for anything has 2 listed as a "parent",
in this case: 3 and 4.
The code then creates an "array" (Split is used to parse it) of the returned
values, 3|4 and then cycles through each, first deleting record 3 itself,
and then searching for anything with 3 as a child (5). The
code will then cycle through using 5, and then later using 6.
After there is nothing more related to 3, the code does the same
thing for 4.
Hope this code helps :) Please give me any feedback and/or suggestions, as I
should be posting this "friendspace" project online soon :)
|
|
Download article
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
- Re-scan downloaded files using your personal virus checker before using it.
- NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
If you don't have a virus scanner, you can get one at many places on the net
including:McAfee.com
|
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
| Other 3 submission(s) by this author
| |
Report Bad Submission
|
Your Vote
|
| |
Other User Comments
|
7/24/2001 1:59:45 AM: cyberwin
Good code. Well thought out. But, I think it is a little bit much! I think there is a much simpler way to attack that problem. (although it take me a bit to figure that out)... However, I am still using this code on my own discussion forum! :o)
Thanks for sharing! Hope to see more articles from you soon.
Andrew Erwin (If this comment was disrespectful, please report it.)
| 2/12/2002 3:39:26 AM: Esa
That is a very neat code, I really love it.
I wonder if you can help me to create a site map from the same table? it relly makes me crazy (If this comment was disrespectful, please report it.)
| 10/9/2002 5:35:08 AM:
Hi, as I know, Access support cascade delete, have to be made relation on the table to it self(if I am not wrong) (If this comment was disrespectful, please report it.)
| 10/9/2002 5:44:17 AM:
Esa, you can see this http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7445&lngWId=4 (If this comment was disrespectful, please report it.)
| 10/11/2002 2:15:32 AM:
Ever heard of referential integrity and cascaded delete. Check your local database provider please ! Greetings (If this comment was disrespectful, please report it.)
|
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)
To post feedback, first please login.
|
|