0
我只是想創建一個json編碼的數據從MySQL結果使用php.I有一個員工詳細信息表,我想從這些json_encoded數組顯示錶數據。在PHP中創建json_encode Mysql
{
"data": [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800"
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
]
]
}
我是新來json_encode,我試着像
$sql_sel = mysqli_query($con,"SELECT * FROM `table`");
$array = array();
$i = 0;
while($res_sel = mysqli_fetch_array($sql_sel)){
$array['data'][$i] = $res_sel['name'];
$i++;
}
$json_val = json_encode($array);
echo "<pre>";
print_r($json_val);
那麼..你的問題是什麼?期望的結果,當前結果? –
閱讀[json_decode()](http://php.net/manual/en/function.json-decode.php) – Saty
JSON不需要'print_r',畢竟它是JSON ** String **。 –