2016-08-21 71 views
0

嚴重性:注意 消息:未定義抵消:0 消息:試圖讓非對象的屬性結果集的錯誤,如果沒有記錄由DB返回 - codiegniter

當記錄在數據庫中有發現沒有錯誤,但是當查詢返回沒有結果時給出上述錯誤。

如何解決?

public function filessearch($id,$type){ 

$this->db->from('files'); 
$this->db->like('FTitle',$id); 
$this->db->where('FBlock','UnBlock'); 
$this->db->where('FFullType',$type); 
$this->db->limit(50); 
$this->db->order_by('FID','DESC'); 
$this->db->group_by('FTitle'); 
$query=$this->db->get(); 
return $query->result(); 

} 
+0

謝謝bro解決了我的問題 –

回答

0

哪裏給你的錯誤不在你向我們展示的代碼中,但我可以識別和猜測問題。

某處在你的代碼中做這樣的事情:

$fileResults = $this->your_model->filessearch($someId, $someType); 

echo $fileResults[0]->some_column; 

什麼情況是,如果沒有結果從數據庫返回的指數爲零[0]不存在。 如果數組不爲空,則首先進行驗證。

if(count($fileResults) > 0) 
    echo $fileResults[0]->some_column;