0
我想通過PHP修改JSON從MySQL和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與json_encode
函數返回有點不同。我應該如何解決它?
PHP代碼:
while($row = mysql_fetch_assoc($select)) {
$r[] = $row;
$items[] = array('x' => $row['unixtime'], 'y' => $row['sensor']);
}
print json_encode($items);
PHP OUTPUT:
[{"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
,不知道如何找出, 請指教。
呵呵謝謝,我從來不認爲它的類型的變量引起 – Nont