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)

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改