我希望用户可以看到他们来自哪里以及有多少评论并按国家/地区分组:
这是对的吗?
<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?
感谢您的帮助。
答案 0 :(得分:1)
在发布的所有代码中,只有查询与此问题相关,因此您需要的查询是:
SELECT country, count(*) as total
FROM comments
WHERE userid = '$userid'
GROUP BY country
答案 1 :(得分:0)
是的,您可以通过修改查询
来实现$sql = mysql_query("SELECT sum(country) as total FROM comments WHERE userid = '$userid' AND GROUP BY country");
你可以退出
echo $row['total']