If you're looking for a solution for how to display a list of latest comments for Drupal 5.x and up, you should install the Views module ,which comes with a view called comments_recent. You can modify the settings of that view to change how many comments get returned.

Note from the moderator: Thank you for sharing the snippet with the Drupal community. In its current state the snippet might present security risks. See Writing secure code for a background on the most common problems.

Specifically, the snippet

  • bypasses node access restrictions; you can perhaps rewrite the query and pass through db_rewrite_sql.

$max = 10;
$query = 'SELECT nid,cid,subject FROM {comments} order by timestamp desc ';
$result = db_query_range($query, 0, $max);
$items = array ();
while ($comment = db_fetch_object($result)) {
	$items[] = l($comment->subject, "node/$comment->nid", NULL, NULL, "comment-$comment->cid");
}
if (count($items)) {
	return theme('item_list', $items);
}