This snippet produces a comma separated list of terms within a given vocabulary, including links to the terms and the number of nodes.
e.g. Term 1 (4), Term 2 (5), Term 3 (6)
Change $vid as required.

// This snippet produces a comma separated list of terms within a given vocabulary
// Includes links to terms and number of nodes.
// Shared by Sverre - September 2006
// Drupal 4.7 tested

$vid = 1; // Change to appropriate vocabulary id

$result = db_query(db_rewrite_sql('SELECT t.tid, t.name, COUNT(*) AS count , parent FROM {term_data} t INNER JOIN  {term_hierarchy} h ON t.tid = h.tid INNER JOIN {term_node} tn USING (tid) INNER JOIN {node} n USING (nid) WHERE t.vid = %d  GROUP BY t.tid, t.name ORDER BY weight, name', 't', 'tid'), $vid);
$items = array();
while ($category = db_fetch_object($result)) {
  $items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid);
}

print str_replace(' | ', ', ', theme('links', $items));

Unknown Column Error

An error "Unknown column 'col_name' in 'on clause'" may occur if you are use this snippet with MySQL > 5.0.x. There are some changes in join proccessing from 5.0.12. I can propose my simple query to solve this error. This query is only for plain vocabularies. Change $result variable to:

$result = db_query(db_rewrite_sql('SELECT t.tid, t.name, t.description, COUNT(*) as count FROM {term_data} t INNER JOIN {term_node} tn ON t.tid = tn.tid WHERE t.vid = %d  GROUP BY t.tid, t.name ORDER BY weight, name', 't', 'tid'), $vid);