3 ms·
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_
by clueless 19y ago
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?
- tlrobinson 19y agoOne query per comment is terrible... I'm glad you realize it's inefficient :)
- domnit 19y agoYou can fetch all of the comments by comment_link_id in a single query, then work with the result to recursively print the tree.