使用 MySQL 查询结果通过 FusionCharts 创建图表

发布于 2025-01-01 16:19:44 字数 1413 浏览 4 评论 0原文

我有这个查询

SELECT DISTINCT (sl.smsstatus), sl.sms_prefix, sum(sl.parts) AS sum
FROM sms_log sl, sms_transaction st
WHERE
      st.user_id = 552
  AND st.customer_id = 1
  AND st.sendtime >= 1328050800
  AND st.sendtime <= 1328309999
  AND st.sms_trans_id = sl.trans_id
GROUP BY sl.sms_prefix 

结果如下:

smsstatus | sms_prefix | sum
----------+------------+-----
rejected  |  963       |  2
received  |  971       |  2

我想根据国家前缀和短信数量在 Fusion Chart 上显示此结果。

这是我获取结果并显示在图表上的代码,但它有一个问题,它仅显示第一行,并且 $total 值错误=3。

我需要在图表上显示(在 XAxis 上“ sms_prefix ”,该值是“总和”的数量)。

谢谢和问候,

$res_smsstat_status = $oSMSStatHandlerCnf->get_stat_country($_user_id, $_customer_id, $s_start_time, $s_end_time);

while ($smsstat_status_row = mysql_fetch_assoc($res_smsstat_status)) {
    $total = $total + $smsstat_status_row['sum'];
    $strXML = "<graph caption='".$oLangHandler->tr("Traffic Graph")."' xAxisName='".$oLangHandler->tr("Delivery Status")."' yAxisName='".$oLangHandler->tr("SMS Amount")."' decimalPrecision='0' formatNumberScale='0'>";
    if ($total > 0) $strXML .= "<set name='".$smsstat_status_row['sms_prefix']."' value='".$total."' color='#87CEFA'/>";
    $strXML .= "</graph>";
    echo renderChartHTML("chart/FusionCharts/Column2D.swf", "", $strXML, "myNext", 790, 300);
}

I have this query

SELECT DISTINCT (sl.smsstatus), sl.sms_prefix, sum(sl.parts) AS sum
FROM sms_log sl, sms_transaction st
WHERE
      st.user_id = 552
  AND st.customer_id = 1
  AND st.sendtime >= 1328050800
  AND st.sendtime <= 1328309999
  AND st.sms_trans_id = sl.trans_id
GROUP BY sl.sms_prefix 

The result as follows:

smsstatus | sms_prefix | sum
----------+------------+-----
rejected  |  963       |  2
received  |  971       |  2

I want to display this result on Fusion Chart based on country prefix and number of SMS.

This is my code to get the result and display on the chart, But it has a problem, It displays only the first row and $total value comes wrongly=3.

I need to display on the chart ( on XAxis " sms_prefix " and the value is the amount of 'sum').

Thanks and Regards,

$res_smsstat_status = $oSMSStatHandlerCnf->get_stat_country($_user_id, $_customer_id, $s_start_time, $s_end_time);

while ($smsstat_status_row = mysql_fetch_assoc($res_smsstat_status)) {
    $total = $total + $smsstat_status_row['sum'];
    $strXML = "<graph caption='".$oLangHandler->tr("Traffic Graph")."' xAxisName='".$oLangHandler->tr("Delivery Status")."' yAxisName='".$oLangHandler->tr("SMS Amount")."' decimalPrecision='0' formatNumberScale='0'>";
    if ($total > 0) $strXML .= "<set name='".$smsstat_status_row['sms_prefix']."' value='".$total."' color='#87CEFA'/>";
    $strXML .= "</graph>";
    echo renderChartHTML("chart/FusionCharts/Column2D.swf", "", $strXML, "myNext", 790, 300);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔女人霸气范 2025-01-08 16:19:44

我对您的代码做了一些更正:

        $res_smsstat_status = $oSMSStatHandlerCnf->get_stat_country($_user_id, $_customer_id, $s_start_time, $s_end_time);

    // Initialize $total to 0 for safe programming

        $total = 0;

    // Initialize $strXML *before* the while loop. If you do this within the loop, then you'll get only 1 chart with all the values summed up.

        $strXML = "<graph caption='".$oLangHandler->tr("Traffic Graph")."' xAxisName='".$oLangHandler->tr("Delivery Status")."' yAxisName='".$oLangHandler->tr("SMS Amount")."' decimalPrecision='0' formatNumberScale='0'>";

        while ($smsstat_status_row = mysql_fetch_assoc($res_smsstat_status)) {
                $total = $total + $smsstat_status_row['sum'];
                if ($total > 0) $strXML .= "<set name='".$smsstat_status_row['sms_prefix']."' value='".$total."' color='#87CEFA'/>";

        }

        $strXML .= "</graph>";

        echo renderChartHTML("chart/FusionCharts/Column2D.swf", "", $strXML, "myNext", 790, 300);

I have made a few corrections in your code:

        $res_smsstat_status = $oSMSStatHandlerCnf->get_stat_country($_user_id, $_customer_id, $s_start_time, $s_end_time);

    // Initialize $total to 0 for safe programming

        $total = 0;

    // Initialize $strXML *before* the while loop. If you do this within the loop, then you'll get only 1 chart with all the values summed up.

        $strXML = "<graph caption='".$oLangHandler->tr("Traffic Graph")."' xAxisName='".$oLangHandler->tr("Delivery Status")."' yAxisName='".$oLangHandler->tr("SMS Amount")."' decimalPrecision='0' formatNumberScale='0'>";

        while ($smsstat_status_row = mysql_fetch_assoc($res_smsstat_status)) {
                $total = $total + $smsstat_status_row['sum'];
                if ($total > 0) $strXML .= "<set name='".$smsstat_status_row['sms_prefix']."' value='".$total."' color='#87CEFA'/>";

        }

        $strXML .= "</graph>";

        echo renderChartHTML("chart/FusionCharts/Column2D.swf", "", $strXML, "myNext", 790, 300);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文