-1

i want to do some country statistics

<?php
$country = mysql_query("SELECT * FROM b_visits WHERE link='$link'");
while($c = mysql_fetch_array($country)){
  $code = $c['c_code'];
  $name = $c['c_name'];

    $broj = mysql_num_rows(mysql_query("SELECT * FROM b_visits WHERE link='$link' AND c_code='$code'"));

  echo "<tr> <td><img style='max-width:20px;max-height:20px;' src='/flags/$code.png'> $name  (<b>$broj</b>) </td> </tr>";   
}  ?>

and its like :

United States (1) Unknown (2) Unknown (2)

like u can see i get 2 times same country for that post i want something like:

Unknow (2)
United Stats (1) etc..

Any help?

goeiu3eu
  • 39
  • 1
  • 8
  • possible duplicate, check http://stackoverflow.com/questions/3695369/sql-how-to-remove-duplicates-within-select-query to find an answer or the other more like these – bakriawad Feb 01 '15 at 21:44

1 Answers1

0

try this:

    <?php
$country = mysql_query("SELECT c_name, count(c_name) as count FROM b_visits WHERE link='$link' group by c_name");
while($c = mysql_fetch_array($country)){
  $broj = $c['count'];
  $name = $c['c_name'];
  echo "<tr> <td><img style='max-width:20px;max-height:20px;' src='/flags/$code.png'> $name  (<b>$broj</b>) </td> </tr>";   
}  ?>
Nishanth Matha
  • 5,993
  • 2
  • 19
  • 28