Get URL Category Name By ID

You are already using the get_term_by() method in your code. That’s the way to get information about your category, i.e.:

$myterm = get_term_by('id', $cat_id, 'category');
if ( $myterm ) {
    echo $myterm->name;
}

PS. I used ‘category’ as taxonomy, you might have a different term (i.e. ad_cat).