具有多个$ [current_session]

时间:2018-11-12 07:23:34

标签: javascript php mysql amcharts

我使用JS amCharts对我的trendx表进行了排序,从而创建了一个切片的饼图。但是我希望根据$[current_session]进行更新。我使用此查询输出了名为Undetected, Detected, Not Supported, Escalate

的4个主要切片
  $query = "select 'Undetected' as trendx , COUNT(*) as counter from jeremy_table_trend  WHERE trendx LIKE '%Undet%'";
  $UNDET = mysqli_query($conn, $query);

  $query2 = "select 'Not Supported' as trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Not Supported%'";
  $NOTSUPORTED = mysqli_query($conn, $query2);

  $query3 = "select 'Escalate' as trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Escalate%'";
  $ESCALATE = mysqli_query($conn, $query3);

  $query4 = "select 'Detected' as trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx NOT LIKE '%Not Supported%' AND trendx NOT LIKE '%Undet%' AND trendx NOT LIKE '%Escalate%'";
  $DETECTED = mysqli_query($conn, $query4);

这是四个主要切片的输出:

enter image description here

这是我的查询,用于显示UndetectedDetected下的子项:

$query5 = "SELECT DISTINCT trendx, COUNT(*) as counter FROM jeremy_table_trend WHERE trendx LIKE '%Undet%' group by trendx";
  $sub_undet= mysqli_query($conn, $query5);

 $query8 = "SELECT DISTINCT trendx, COUNT(*) as counter FROM jeremy_table_trend WHERE trendx NOT LIKE '%Not Supported%' AND trendx NOT LIKE '%Undet%' AND trendx NOT LIKE '%Escalate%' group by trendx";
  $sub_detected = mysqli_query($conn, $query8);

这是我单击“未检测到”的输出:

enter image description here

这是我的代码,用于输出值:

var types = [  
    <?php while($row = mysqli_fetch_array($UNDET)): ?>

  {
    "type": "<?php echo $row['trendx'] ?>",
    "percent": "<?php echo $row['counter']; ?>",
    "subs": [
        <?php while($row = mysqli_fetch_array($sub_undet)): ?>

        {
            "type": "<?php echo $row['trendx'] ?>",
            "percent": <?php echo $row['counter']; ?>
        },

        <?php endwhile; ?>
    ]
  },

    <?php endwhile; ?> 




    <?php while($row = mysqli_fetch_array($NOTSUPORTED)): ?>

  {
    "type": "<?php echo $row['trendx'] ?>",
    "percent": "<?php echo $row['counter']; ?>",
    "subs": [
        <?php while($row = mysqli_fetch_array($sub_notsupported)): ?>

        {
            "type": "<?php echo $row['trendx'] ?>",
            "percent": <?php echo $row['counter']; ?>
        },

        <?php endwhile; ?>
    ]
  },

    <?php endwhile; ?> 


    <?php while($row = mysqli_fetch_array($ESCALATE)): ?>

  {
    "type": "<?php echo $row['trendx'] ?>",
    "percent": "<?php echo $row['counter']; ?>",
    "subs": [
        <?php while($row = mysqli_fetch_array($sub_escalate)): ?>

        {
            "type": "<?php echo $row['trendx'] ?>",
            "percent": <?php echo $row['counter']; ?>
        },

        <?php endwhile; ?>
    ]
  },

    <?php endwhile; ?> 



    <?php while($row = mysqli_fetch_array($DETECTED)): ?>

  {
    "type": "<?php echo $row['trendx'] ?>",
    "percent": "<?php echo $row['counter']; ?>",
    "subs": [
        <?php while($row = mysqli_fetch_array($sub_detected)): ?>

        {
            "type": "<?php echo $row['trendx'] ?>",
            "percent": <?php echo $row['counter']; ?>
        },

        <?php endwhile; ?>
    ]
  },

    <?php endwhile; ?> 


];

这正常运行,但是我知道它很混乱,在过滤表时如何根据$[current_session]输出饼图?

因此,我尝试对我的4个切片执行此查询,但我不知道该如何在我的子项中执行此操作,请帮助我,我需要完成此操作:

SELECT
    CASE
        WHEN trendx LIKE '%Undet%' THEN 'Undet'
        WHEN trendx LIKE '%Escalate%' THEN 'Escalate'
        WHEN trendx LIKE '%Not Supported%' THEN 'Not Supported'
        ELSE 'Supported'
    END
    AS trendx
    , COUNT(*) AS counter
FROM jeremy_table_trend $[current_query]   
GROUP BY
    CASE
        WHEN trendx LIKE '%Undet%' THEN 'Undet'
        WHEN trendx LIKE '%Escalate%' THEN 'Escalate'
        WHEN trendx LIKE '%Not Supported%' THEN 'Not Supported'
        ELSE 'Supported'
    END

在这里查看我的完整代码,我需要完成此操作,我尝试了我知道的所有解决方案,但我做不到。

http://plnkr.co/edit/nrbYC0Jqgyl2QlAkcHv0?p=preview

0 个答案:

没有答案