我在數據庫中有這個json encode
,我想只是回聲值name_r
在foreach
,它是怎麼回事?PHP json從數據庫解碼
[{
"name_r": "saeed",
"units": ["salam", "11", "11", "khobe", "22", "22", "salam"],
"price_change": ["33", "33", "33", "44", "44", "44"]
}, {
"name_r": "salavat",
"units": ["55", "55", "khobe", "66", "66"],
"price_change": ["77", "77", "77", "88", "88", "88", "99", "99", "99"]
}]
這是我的PHP,有錯誤(Message: Undefined index: name_r - Line Number: 179
):
$query = $this->db->query("SELECT * FROM table ORDER BY id desc");
$data = array();
foreach ($query->result() as $row)
{
$data[] = json_decode($row->residence,true);
echo $data["name_r"].'<br>'; //Line Number: 179
}
* residence *列是否包含發佈的JSON數據? – Gumbo