douchengchen7959 2014-11-21 14:46
浏览 45
已采纳

在Highcharts的x轴上打印会话变量(数组)

I need to print dates I get a sql query. I keep these dates in an array, and the array put it in a session ($ _SESSION ['dates'] = $ dates). The problem is that when I do an "echo" of the year, the month and the day, I do not do returns or strange numbers. I tried with "json_encode", but something I'm doing wrong. Thank you all.

In this "php" I keep the dates in an array and session:

<?php

    $datayMin = array();
    $datayMax = array();
    $dataEMF = array();
    $dates = array();

    $i = 0;

        while($row = mssql_fetch_array($consulta)) {

            //Suma de EMA + UMA(error máximo admitido + incertidumbre máxima admitida)
            $valor = $row[5] + $row[6];

            $dataEMF[] = $row ["EMF"];
            $datayMin[] = $row ["EMF"] - $row ["UMF"]; //Punt més baix (Error - Incertesa)
            $datayMax[] = $row ["EMF"] + $row ["UMF"]; //Punt més alt(Error + Incertesa)
            $dates[$i] = $row[2];


            $html .= '  <tr>
                            <td bgcolor="#FFFFFF" style="border-radius: 3px;"><font size="1" face="Verdana">'.$row[0].'</font></td>
                            <td bgcolor="#FFFFFF" style="border-radius: 3px;"><font size="1" face="Verdana">'.htmlentities($row[1]).'</font></td>
                            <td bgcolor="#FFFFFF" style="border-radius: 3px;"><font size="1" face="Verdana">'.$row[2].'</font></td>
                            <td bgcolor="#FFFFFF" style="border-radius: 3px;"><font size="1" face="Verdana">'.$row[3].'</font></td>
                            <td bgcolor="#FFFFFF" style="border-radius: 3px;"><font size="1" face="Verdana">'.$row[4].'</font></td>
                            <td bgcolor="#FFFFFF" style="border-radius: 3px;"><font size="1" face="Verdana">'.$valor.'</font></td>
                            <td bgcolor="#FFFFFF" style="border-radius: 3px;"><font size="1" face="Verdana">'.$row[7].'</font></td>
                    </tr>';
            $i++;
        }

        echo $dates[0];


        $_SESSION["dates"] =$dates;  // PUT ARRAY INTO SESSION!

        echo var_dump($_SESSION["dates"]);

        echo($html);

        ?>

This script (Highcharts function), print the results (not working properly): example -> [Date.UTC(year, month, day), value]

series: [{
            name: 'EMF',
            type: 'line',
            zIndex: 10,
            data: [[Date.UTC(<?php echo substr(json_encode($_SESSION["dates"]["0"]), -4); ?>, <?php echo substr(json_encode($_SESSION["dates"]["0"]), 3,2); ?>-1, <?php echo substr(json_encode($_SESSION["dates"]["0"]), 0,2); ?>), 0],
            [Date.UTC(2013, 10, 10), 0.6 ],

Finally say that the format returned by the query is 2/12/2014. And this is how I want it!

  • 写回答

1条回答 默认 最新

  • douganggu4392 2014-12-01 09:39
    关注

    In the json_encode add this flag, example: json_encode($_SESSION["dates"]["0"], JSON_NUMERIC_CHECK)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 易语言编写cs.16 绘制 矩阵出现了点问题 不知道这个矩阵可不可以使用
    • ¥15 k210显示failed init to model
    • ¥15 Evil-droid生成的APK手机已经下载但无法建立任务
    • ¥25 c语言韩信点兵的变式
    • ¥15 怎么根据书上的例子完成这个问题呢?
    • ¥15 ECharts 增加Zoom,整行包括右边的Text一起滑动
    • ¥15 关于网上一个easyx制作的见缝插针小游戏(c++)
    • ¥15 开地址法双散列函数处理碰撞
    • ¥15 想问一下这个是什么情况 虚拟机Linux打不开了
    • ¥15 联通光猫掉注册了怎么重新注册上去