$query = "
SELECT type,
COUNT(name1) as name_a,
COUNT(name2) as name_b
FROM products
GROUP BY type";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "There are ". $row['name_a'] ." ". $row['type'] ." items.";
echo "<br />";
}