1

我想让用户可以看到他们来自哪里以及有多少评论并按国家/地区分组:

这个对吗?

<script type='text/javascript'>
 google.load('visualization', '1', {'packages': ['geochart']});
 google.setOnLoadCallback(drawRegionsMap);

  function drawRegionsMap() {
    var data = google.visualization.arrayToDataTable([
      ['Country', 'Politics'],
      <?php 
      $sql = mysql_query("SELECT country FROM comments WHERE userid = '$userid' AND GROUP BY country");
      $output = "";
      $countpeople = mysql_num_rows($sql); 
      while( $row = mysql_fetch_array($sql)){
          }
        echo $output;
      ?>
    ]);

    var options = {'backgroundColor': '#E9F6FD'};

    var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
    chart.draw(data, options);
};
</script>

有没有办法进行 SELECT SUM?

感谢您的帮助。

4

2 回答 2

1

在发布的所有代码中,只有查询与此问题相关,因此您需要的查询是:

SELECT country, count(*) as total
FROM comments
WHERE userid = '$userid'
GROUP BY country
于 2013-04-20T12:50:56.163 回答
0

是的,您可以通过修改查询来做到这一点

$sql = mysql_query("SELECT sum(country) as total FROM comments WHERE userid = '$userid' AND GROUP BY country");

你可以出去投入

echo $row['total']
于 2013-04-20T12:42:41.817 回答