gpt4 book ai didi

php - 在 php 脚本和 dygraphs 中使用 new date()

转载 作者:行者123 更新时间:2023-11-29 20:12:40 26 4
gpt4 key购买 nike

我正在尝试从 mysql 检索数据,然后将数据传输到 dygraphs

那么什么可以直接在 javascript 中工作

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

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

使用 php 从数据库中检索值不起作用:

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."],";


};

?>

谢谢:)

最佳答案

最后,我将数据加载为 CSV 格式

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.'\n"'." +". "\n";
}



};

关于php - 在 php 脚本和 dygraphs 中使用 new date(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39984649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com