我是新手,無法理解爲什麼會發生這種情況。我從數據庫中獲取的結果,他們是:Codeignitor:嚴重性聲明消息數組到字符串的轉換
ArrayArray ([0] => stdClass Object ([id] => 1 [box] => draggable1 [xorder] => 1 [descp] => Y) [1] => stdClass Object ([id] => 2 [box] => draggable2 [xorder] => 2 [descp] => Z) [2] => stdClass Object ([id] => 3 [box] => draggable3 [xorder] => 3 [descp] => X))
我想打印單個值,如僅從數組列表打印id value 1
或box value draggable1
。但問題是,當我申請
echo $result1['data'];
給出了錯誤:
Severity: Notice
Message Array to String conversion
類似,同時進一步做努力:
echo $result1['data']['id']; //id is field name
給我的錯誤:
undefined index : id
,最後當我厭倦了這樣做:
print_r($result1['data'][0]);
和打印結果
stdClass Object ([id] => 1 [box] => draggable1 [xorder] => 1 [descp] => Y)
但是當我這樣做:
print_r($result1['data'][0]['id']);
給出了錯誤:
Fatal error: Cannot use object of type stdClass as array
我按照這個帖子這是關係到我,但我不知道爲什麼我不能這樣做Codeigniter : displaying query result in controller
這裏是我的功能:
public function index()
{
$id=$this->input->post('name');
$result1['data']=$this->drag_model->getcoordinates();
$result2['data']=$this->drag_model->getva($id);
echo $result1['data']['id'];
print_r($result1['data'][0]['id']);
// array('id'=>);
// $this->load->view('drag/drag_view');
$this->load->view('drag/dragswap',$result1);
// $this->load->view('LoginN/login_view');
}
請幫助.....
Rizier123我已經提到過的原因,並在下面我提到了我最近的帖子,但我去失敗 – giantmalik