the associative index for the COUNT(*) expression is actually something like $row['COUNT(*)']. to simplify this, add an alias name for the COUNT(*) expression in the query and use that alias name for the associative index.
next, both of the query examples you have shown will/probably match at most one row. why you are using a loop to fetch the data. just fetch the single row without the loop.