我想通过 PHP使用Rickshaw显示 MySQL 的最后数据
它需要看起来像这样:
[
{
"data": [ { "x": 1350995278, "y": 26.12 },
{ "x": 1350995276, "y": 26.19 },
{ "x": 1350995273, "y": 26.12 },
{ "x": 1350995271, "y": 26.19 },
{ "x": 1350995268, "y": 26.19 } ]
}
]
但我的 PHP with json_encode
function 返回它有点不同。我应该如何解决?
PHP代码:
while($row = mysql_fetch_assoc($select)) {
$r[] = $row;
$items[] = array('x' => $row['unixtime'], 'y' => $row['sensor']);
}
print json_encode($items);
PHP 输出:
[{"x":"1350996886","y":"26.06"},
{"x":"1350996884","y":"26.06"},
{"x":"1350996881","y":"26.06"},
{"x":"1350996879","y":"26.06"},
{"x":"1350996876","y":"26.06"},
{"x":"1350996874","y":"26.06"},
{"x":"1350996871","y":"26.06"},
{"x":"1350996869","y":"26.06"},
{"x":"1350996866","y":"26.06"},
{"x":"1350996864","y":"26.06"}]
我不需要""
之后x
:和Y
:我是新手,PHP
不知道如何弄清楚,请指教。