回波值我插入數據庫表中的值的行,現在我想用json_encode附和他們,但我有以下錯誤:問題與數據庫
PHP:
$name_tour = $this->input->post('tour_name');
$query = $this->db->query("SELECT * FROM tour_foreign WHERE name LIKE '$name_tour' ORDER BY id desc");
$data = array();
foreach ($query->result() as $row) {
$data_rp = json_decode($row->residence_p, true);
$data[] = array(
'residence_p' => $data_rp,
);
}
echo json_encode($data);
echo '<p>';
var_dump($data);
輸出以上PHP代碼:
[{"residence_p":null}] // This is output of json_encode($data)
array(1) { [0]=> array(1) { ["residence_p"]=> NULL } } // This is output of var_dump($data)
數據在數據庫:(此數據櫻雪rt by json_encode)
[{
"start_date": ["1111", "2222"],
"end_date": ["1111", "2222"],
"price_change": ["1111", "2222"]
}, {
"start_date": ["3333", "444"],
"end_date": ["3333", "4444"],
"price_change": ["3333", "4444"]
}, {
"start_date": ["5555", "6666"],
"end_date": ["5555", "6666"],
"price_change": ["5555", "6666"]
},]
我該怎麼辦?
什麼是錯誤?你期望看到什麼? – rid
我想從數據庫中獲取數據,請參閱代碼清楚,我想要什麼。 –