需要针对fusionchart的SQL查询,合并团队结果的总计

时间:2017-07-17 02:22:54

标签: php sql fusioncharts

目前我有一个名为members的SQL数据库,其中包含以下列。

  • MEMBERID
  • 用户名
  • 电子邮件
  • 密码

我试图在条形图上显示两个不同颜色系列的条形图。一个显示目标,一个显示总数,但我希望由团队。

目前,我有9个团队的337名学生。每个学生都有自己的目标,总数是他们实际筹集的。我想让图表将所有类似的团队组合在一起,以显示每个团队正在做的事情。

下面是当前代码,它为我提供了图表,但只显示了每个团队中的1名学生,而不是团队中所有学生的累积数。

    <?php
$rank = 0;
$sql = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM members WHERE type = 'student' ORDER BY  username ASC");
while($row = mysqli_fetch_object($sql)) 
{
    echo "{\"value\":\"";
        $rank = $rank + 1;
        echo "$row->total\"},";
}
?>
            ]
        },
        {
            "seriesname": "Target",
            "data": [
<?php
$rank = 0;
$sql = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM members WHERE type = 'student' ORDER BY  username ASC");
while($row = mysqli_fetch_object($sql)) 
{
    echo "{\"value\":\"";
        $rank = $rank + 1;
        echo "$row->target\"},";
}
?>

为了得到这个,我需要调整什么? 数据样本如下

memberID    username     team   email   target  password    type    total
1191        Student 27   Team 9         3624                student 250
1280        Student 116  Team 7         986                 student 100
1392        Student 228  Team 4         1755                student 10
1318        Student 154  Team 8         2170                student 200
1282        Student 118  Team 7         986                 student 57
1458        Student 294  Team 6         620                 student 479
1174        Student 10   Team 5         2672                student 195
1390        Student 226  Team 4         1755                student 775
1446        Student 282  Team 3         1091                student 1090
1193        Student 29   Team 9         3624                student 3000
1346        Student 182  Team 8         2170                student 47
1187        Student 23   Team 9         3624                student 52
1232        Student 68   Team 7         986                 student 752
1241        Student 77   Team 7         986                 student 63
1234        Student 70   Team 7         986                 student 800
1236        Student 72   Team 7         986                 student 12
1391        Student 227  Team 4         1755                student 0
1479        Student 315  Team 6         620                 student 1

0 个答案:

没有答案