I'll agree with NogDog, here. There may be some sort of confusion about what is being counted. When I looked at the code I saw:
foreach ( $categories as $c ) {
if($c == $catID) {
$abovequery = $db->query("SELECT * FROM cart_blk_shop_products WHERE productLive = 1 AND productCATID = $id");
As it stands, the results returned by this query don't depend on $categories at all, so probably shouldn't be in the loop ($catID doesn't seem to be defined).
I'm going to guess that the query is only supposed to run no more than once: in fact, the entire body of that loop is supposed to run no more than once (when $c==$catID), assuming that $c can only appear in $categories once. In which case the entire loop is redundant, since the only other thing it does is count the number of elements in the $categories array.