How to show a number count of photos attached to a classified ad.

I am trying to get my classifieds listing page to display a count of the pictures attached to each classified custom post type.

So far I have tried the following code inserted into the loop-taxonomy.php file in the classifieds plugin directory.

$id = get_the_ID();
$total_attachments = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' && ID=$id");
echo $total_attachments;

This seems to output "0" no matter how many pictures are attached to the post.

Any hints on the right direction to go from here would be great!

Also if someone knows how to limit the number of photo uploads allowed per classified post I am trying to find the answer to that as well.