News for hackers. Stuff that matters.
Re:Ask YC: what's the best way to model a threaded comment s... by clueless on Sunday March 16, 2008 @11:30AM (#138201)
Re:Ask YC: what's the best way to model a threaded comment s... by clueless on Sunday March 16, 2008 @02:32PM (#138304)
Also here is MY ineffecient way of doing it:

function article($link){

print_story($link->id);

print_comment(0,$link->id);

}

function print_comment($parent_id, $link_id){

$comments = $db->get_col("SELECT comment_id FROM table_comments WHERE comment_link_id=$link_id and comment_parent = $parent_id ORDER BY comment_votes DESC");

if ($comments) {

		$comment = new Comment;
		foreach($comments as $comment) {		
				$comment->print();
			}
				print_comment($comment_id,$link_id);
		}
								
	}
}

TABLE `table_comments` (

  `comment_id`, `comment_parent`, `comment_link_id`, `comment_votes`
)

If you store and manipulate all the data in memory, I don't see why this would be that bad?

Re:Ask YC: what's the best way to model a threaded comment s... by domnit on Monday March 17, 2008 @10:33AM (#138919)
You can fetch all of the comments by comment_link_id in a single query, then work with the result to recursively print the tree.
Re:Ask YC: what's the best way to model a threaded comment s... by tlrobinson on Sunday March 16, 2008 @05:07PM (#138410)
One query per comment is terrible... I'm glad you realize it's inefficient :)
Re:Ask YC: what's the best way to model a threaded comment s... by brett on Sunday March 16, 2008 @03:17PM (#138331)
I went with more or less what nostrademons described. So far it's working well.