gpt4 book ai didi

mysql - Highstock mysql json比较多个系列

转载 作者:行者123 更新时间:2023-11-30 01:37:28 24 4
gpt4 key购买 nike

请帮助创建一个查询!这是我的查询使用 PHP 以 JSON 形式检索数据的工作示例:

<?php
$con = mysql_connect("localhost","user","password");

if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("admin_accounting", $con);

$result = mysql_query("SELECT unix_timestamp(date), sum(ksi2k) FROM accounting where lhc_vo like 'ops' group by year(date), month(date)");
$rows = array();
$rows['type'] = 'area';
$rows['name'] = 'Ops';
while($r = mysql_fetch_array($result)) {
$rows['data'][] = $r[0]*1000;
$rows['data'][] = $r[1];

array_push($rows);
}

print json_encode($rows, JSON_NUMERIC_CHECK);

mysql_close($con);
?>

JSON 结果如下所示:

{"type":"area","name":"Ops","data":[1167664515000,0,1170342915000,0,1172762115000,0,1175436915000,0,1178028915000,0]}

但我需要 JSON 结果应该如下所示:

{"type":"area","name":"Ops","data":[[1167664515000,0],[1170342915000,0],[1172762115000,0],[1175436915000,0],[1178028915000,0]]}

我将非常感谢您的帮助

最佳答案

while($r = mysql_fetch_array($result)) {
$rows['data'][] = array($r[0]*1000, $r[1]);
}

关于mysql - Highstock mysql json比较多个系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16668566/

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