-1
我的問題是從SQL獲取數據,動態地更新圖表 MySQL數據就像從PHP獲取MySQL數據到JSON
id | age
1 | 12
2 | 21
3 | 31
4 | 11
5 | 31
,我想呼應這樣
[1,12] , [2,21] , [3,31] , [4,11] , [5,31]
我有嘗試這樣
$sql = "SELECT id, age FROM tes";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$tes = $row['tes'];
$a = array($id,$tes);
echo json_encode($a, JSON_PRETTY_PRINT);
}
,但最終就像
[1,12] [2,21] [3,31] [4,11] [5,31]
請幫我...
您所需的輸出無效JSON。這正是你想要的嗎? – CollinD
如果連接JSON字符串,則不會獲得JSON,就像拼接JPEG圖片不會產生更大的圖片一樣。 –