dongtanliefang8765 2016-10-11 18:54
浏览 30

在php脚本和dygraphs中使用新的date()

I'm trying to retreive data from a mysql then transfert my data to dygraphs

So what working directly in javascript

 new Dygraph(document.getElementById("graphdiv2"),
          [

[ new Date("2009/07/12"), 100, 200 ],
[ new Date("2009/07/19"), 150, 220 ]
          ],
          {
            labels: [ "x", "A", "B" ]
          });

And what is not working with usage of php to retreive value from data base :

new Dygraph(document.getElementById("graphdiv"),
          [ 

            <?php
            mysql_connect("xxx.xxx.xxx.xxx", "MyUser", "MyPassword") or
            die("Impossible de se connecter : " . mysql_error());
            mysql_select_db("esync");


            $result = mysql_query("SELECT ID, _date, ESYNC_TAGSHISTORY.Val
            FROM ESYNC_TAGSHISTORY
            INNER JOIN ESYNC_TAGS ON ESYNC_TAGSHISTORY.TAGID=ESYNC_TAGS.ID
            WHERE ESYNC_TAGS.NAME='I_TT_21052'  AND ESYNC_TAGS.STATIONID=1 AND (_date BETWEEN now()-INTERVAL 45 MINUTE AND now());");

            $return_arr = array();

            //while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $numResults = mysql_num_rows($result);  

            $counter = 0;           

            while ($row = mysql_fetch_array($result)) {

                $date = date_create($row['_date']);
                $date = $date->format('d/m/y H:i:s');   //format the date
                $b=$row['Val'];


            echo "[".$date.",".$b."],";


            };

            ?>  

Thanks :)

  • 写回答

1条回答 默认 最新

  • doudi4621 2016-10-12 20:10
    关注

    Finally, i've loaded my data with CSV format as

    while ($row = mysqli_fetch_array($result)) {
    
    
                    $a= date('Y/m/d H:i:s',strtotime($row['_date']));  //converting into required format of date
    
    
    
                    $b=$row['Val'];
    
                    if (++$counter == $numResults) {
                    echo  '"'.$a.",".$b.'"'." ,";
                    } else {
                    echo  '"'.$a.",".$b.'
    "'." +". "
    ";
                    }
    
    
    
                };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败