--- comment.module.4.7.5 2007-01-03 16:56:58.000000000 -0500 +++ comment.module 2007-01-05 14:17:08.000000000 -0500 @@ -585,11 +585,21 @@ function comment_save($edit) { // by retrieving the maximum thread level. $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid'])); - // Strip the "/" from the end of the thread. - $max = rtrim($max, '/'); + if($max == '') + { + $thread = int2vancode(0) . '/'; + } + else { + // Strip the "/" from the end of the thread. + $max = rtrim($max, '/'); - // Finally, build the thread field for this new comment. - $thread = int2vancode(vancode2int($max) + 1) .'/'; + // We need to get the value at the correct depth. + $parts = explode('.', $max); + $firstsegment = $parts[0]; + + // Finally, build the thread field for this new comment. + $thread = int2vancode(vancode2int($firstsegment) + 1) .'/'; + } } else { // This is comment with a parent comment: we increase