List node count for each node type

This snippet is will return a table with each node type and the number of nodes published for each type over the past three years

Snippet:

<?php
#in template.php:
function custom_count_pull(){
   
$sql = "SELECT type, COUNT(nid) AS number, FROM_UNIXTIME(created, '%Y')  AS createdate FROM {node} GROUP BY type, createdate ORDER BY createdate DESC";
   
$result = db_query($sql);
   
$article_count = array();

    while (
$data = db_fetch_object($result)){
        if (isset(
$article_count[$data->type])) {
      
           
$article_count[$data->type][$data->createdate] = $data->number;
        } else {
           
$article_count[$data->type] = array($data->createdate => $data->number);
        }
    }
   
$today = date("Y");
   
$years = array($today-2,$today-1,$today);

   
$output .= "<table><tr><th>Type</th><th>{$years[0]}</th><th>{$years[1]}</th><th>{$years[2]}</th></tr>";  
    foreach (
$article_count as $type => $value) {
       
$real_type_name = node_get_types('name', $type);
       
$output .= "<tr> <td>$real_type_name</td>";

        foreach (
$years as $year) {
            if (
$value[$year]):
           
$output .= "<td>{$value[$year]}</td>";
            else:
           
$output .= "<td>0</td>";
            endif;
        }
       
$output .= "</tr>";
    }
   
$output .= "</table>";
    return
$output;
}
?>


<?php
#in node.tpl, page.tpl or block.tpl
print custom_count_pull();
?>