2016-09-27 51 views
0
<?php  
//image formation 
$imag_sel=$this->db 
->select('image') 
->where(['id',$id1]) 
->get('borrow_user'); 

$fil=$imag_sel->result();//result for code 
print_r($fil);//return image but not returning anthing it's gave "array()" 
?> 
+1

把$ imag_sel = $這個 - >分貝 - > select('image') - > where('id',$ id1) - > get('borrow_user');在你的代碼或檢查查詢是否存在於表中的ID –

+0

'$ imag_sel'這是你的實例嗎?或'$ this-> db'? – devpro

+0

感謝abhijit您的評論我得到了答案。通過使用這個代碼$ arr = array('id'=> $ id1); \t $ imag_sel = $這個 - >分貝 \t - >選擇( '圖像') \t - >其中($ ARR) \t - >得到( 'borrow_user'); \t $ fil = $ imag_sel-> result(); \t print_r($ fil); –

回答

0

對於任何人想知道,問題是「where」子句。

哪裏可以做兩種方式:

方法1:

->where('field', $value) 

要鏈接的where子句,e.g:

$this->db 
    ->where('name', $name) 
    ->where('age', $age) 
    ->get('table'); 

或可選擇地使用數組。

方法2:

$where = array(
    'name' => $name, 
    'age' => $age, 
); 
$this->db 
    ->where($where) 
    ->get('table'); 

你也不必鏈它們。你可以做他們的程序:

$this->db->where('name', $name); 
$this->db->where('age', $age); 
// or 
$this->db->where($where); 

$this->db->get('table'); 

第一個是清潔的,如果你有一個where子句,但多是更好的使用數組(也允許在需要動態數組建築)

+1

我們可以隨時使用where子句方法。 –

+0

確實,但我的觀點是你不僅限於一種方式。 –

+0

改進的答案可以獲得更多的解釋。 –

0

變化這條線

->where(['id',$id1]) 

->where('id',$id1) 
+0

我認爲這會顯示一個錯誤 - > where(['id',$ id1)這是不正確的語法。 –

+0

@HarshJain這一個也是一個可能的語法。我認爲你在'$ id1'之後因'''而犯了錯誤。 – Shihas