Friday, 9 August 2013

Count of different values in MySQL table not adding correctly

Count of different values in MySQL table not adding correctly

I am trying to get a count of the number of different countries I have in
a table but can't get the right result when I echo it out with php.
although phpmyadmin gives the correct answer. This is my query:
$sql2 = "SELECT count(*) as country FROM tpf_parks GROUP BY country" ;
$result2 = $pdo->query($sql2);
foreach ($result2 as $row2)
and this is how I am diplaying it
echo $row2[ 'country' ]
On if I run the query on phpmyadmin I get the correct answer of 17. When
run through the above php it returns 56. What have I done wrong?

No comments:

Post a Comment