Use wp_list_categories
instead,
<?php
$args = array(
'hierarchical' => true,
'child_of' => 42, //parent category
'hide_empty' => 1, //hide empty categories (set to 0 to show)
);
wp_list_categories($args);
?>
A full list of parameters for wp_list_categories
can be found HERE
As you can see its highly customizable simply by adding extra arguements to the array stored in the $args
variable that we later pass to the wp_list_categories
function.
Note: Adding the child_of => ID
argument you can specify the parent ID of the category for which you want to retrieve category terms for. Be aware that if there are no posts in the parent category, it will not show, in which case you may try setting hide_empty => 0
instead.
UPDATE
Well, instead of writing this from scratch myself, Scribu already has thankfully, so please take a look at the following link for more details;
http://scribu.net/wordpress/extending-the-category-walker.html