Galore
In the same fashion as the Cure's "Galore" album, eZabel is proud to present to you some of the best of the best when it comes to links. Sing along...
- Remember the McDonald's chicken head? Well, it turns out McDonald's is now serving rat heads too... ick.
- Also, a new Swedish music video! This is in the same vein as the previous one, "Hatten ar din."
- This is very funny. A white defendant posed as a black teen and was able to walk out of the courtroom scott-free.
- This 3rd grader got suspended because he drew a picture of a soldier with a knife in his hand. Apparently, it was "upsetting to other students."
- Ok, this is weird. This 84 year old guy wants a son. He's infertile though. So what to do? Clone yourself and raise yourself as a baby!
- Also, check out this cool computer backback! Sweet!
That was enlightening, wasn't it?
AI Summary
25 Comments
OK thats not a back pack. You carry it like a briefcase or use the shoulder strap. *You* try strapping an ATX case with power supply and hard drives to your back. hahaha.
(OK, that was really lame geek humor)
HAHAHA!!! I knew somebody would comment on that. Hahaha! I know it's not a backpack, but, who cares, it's funnier as a backpack.
getting a hernia is now laughing matter sir.
now=no. And I'm an idiot.
woaaaaaaah dean said this about himself
Oh, dean, give me your best guess as to how I wrote the comment threading algorithm on here to work.
(Note: I did not look at your database structure diagram so I assumed some things)
OK. Each comment is stored in a database by 'News Item Number' and 'Comment Number' (these two fields compose a compound primary key).
The comment entity (row) contains the following fields as well: comment title (by default "re:'News Item'"), comment text, and date info or whatever, and it also contains: *the comment number of the parent comment*. (very important for threading purposes.
When a user clicks "Reply to Story" a new record is put in the database with a Comment id automatically generated by incrementing the last comment id by 1 (or a similar method). The Parent Comment id is set to 0 or -1 or something like that.
When a user replies to an *already* existent comment, the same thing happens except that the Parent comment id field is set to the number of the comment being replied to.
This is the part that could be different, but its how I'd do it:
So as the page is being created on the server-side, it goes through all the comments for a particular story in order (1,2,3,4). It puts these into some kind of List (array, etc.). The List contains n records composed of the comment fields plus one more field: Indent.
If the Story is the parent, then Indent is 0 and the comment is added to the end of the list. If another comment is the parent, then the current comment is *inserted* into the list after the parent comment (which is found via a search) and the current comment's Indent is set to the parent's Indent + 1.
(Display)
Now the array is gone through sequentially. The comment at index i is printed indented the amount specified by the comment's Indent field (which could be dynamically generated as above or possibly held in the database)
I believe this would work. It's my first guess, and it seems a little computationally expensive, so let me think about it a little bit more.
Also I did not look at your database structure, so I could be wrong on my assumptions, could you post the link to that diagram?
Hey, that was too hard for me to understand, could you please express your logic in a C++ program?
Just kidding.
Anyway, wow, Dean! Great job, man. You came very very close to figuring out most of it. Your logic would work fine, but that's just not how I implemented it. I don't have an "Indent" column in my comments table. But you hit the nail on the head with the -1 parent_id for the comments replied to the story. You have everything exactly right up the actual array/indent part.
I'll give you a hint. "recursive"
Any more ideas?
both of you STOP!!! i cant take all this computer jargon
ok hmm I gave you the linear "hack" solution. Now here's how I'd do it in Java using objects and recursion.
**************************************************************************
Have a class called Node that contains all comment specific information plus an Enumeration of Node objects (children Nodes). Initially, go through all elements of the table, creating new Node objects with comment specific information, and *initially empty* Child Node List. For simplicity's sake, we have a method called void addNode(Node x) which adds the specified Node to *this* Node's child List. Put these newly created Nodes into a hash table, with hash keyed on comment number.
Oh, I almost forgot. Create a root Node with comment id = -1.
**************************************************************************
One could populate the Node Tree by going through the hash linearly (1,2,3...) and for each Node found, get a reference to its parent from the hash into a variable named "parent", and calling parent.addNode(this); This will give you a Comment node tree.
**************************************************************************
The tree is then printed recursively. printNodeAndChildren(Node rootNode) is called. It (1) prints current Node's info. (2a)(if children exist) for each child x (in Enumeration) calls printNodeAndChildren(x) and returns. (2b)(no children) just returns.
**************************************************************************
I could do it another way if I do incremental "Selects" to the database, instead of my one "Select * from comment" at the very beginning.
Do you query the database multiple times during the algorithm, or just once at the beginning like I did?
If I had multiple queries, I could forget about hashtables and Node Objects I think. This is how I'd do it that way:
have a function called printComments(int p_id), and call printComments(-1) in your page creation code.
STEP 1) Recordset recs = EXECUTE("Select * from comment where parent_id="+p_id);
STEP 2) For each record in recs:
STEP 2a)Print rec info (comment, date, etc.)
STEP 2b)call printComments(thisrec.comment_id) //pass this record's comment number as the parent_id
STEP 3)If no records, then this comment has no children (actually no comments in the database have this comment as its parent) so just return.
Basically, the difference between my two ideas is database retrieval time verses computation time. One is database-intensive, and the other is computationally-intensive.
You got it, dean. I went the database-intensive route. I'm not exactly sure which is the best way, but for now, it was the easiest way for me to accomplish the task in ColdFusion, which is not object oriented. The recursive call also keeps track of how many times it has been called for a comment, and this is how I output the indent level.
Guys...i know ian is definitely a certified genius, and dean...well, he's proving himself to me as well. But all this java junk doesn't get you nowhere. to be really smart, you have to know calculus and be able to apply it to computer programming, by intergrating the recursive variable functions into to the nodes within the class, then differentiate the entire function into terms of f'(x), thereby being able to graph your results...if you continue to differentiate, you will eventually find that f''(x) gives you your points of inflection, where you can apply the rest of the nodes of the class...whoopdeedooo i don't even know what i'm talking about!
actually the really funny thing is, I have done this. I took a class called Numerical Methods of Computation in College, cause I was a minoring in Applied Mathematics. And we had to write all these programs in C that would produce tables of figures for differential equations (which is like calculus on acid) using different aproximation algorithms. Anyway.
Actually, I wonder if the funny thing is that you had to do it for a class... and I did it for fun. Heh...
ian, you can take all my classes for fun if you want, and I'll take care of ezabel for a while...nobody will be the wiser.
Matt, you'd give up the opportunity to further your C++ knowledge?.......I'm ashamed to know you. :)
ohhh i most definitely would!
Ian, i think you should hire this guy.
how is it possible that this this modified..when that tool wasnt available til like a month ago
dang you're so observant. it's because i had the ability to modify comments for a LONG time, and I actually fixed dean's html for him sometime in october.
just a guess.
very nice research ian. good job!
by