2013-08-28 26 views
4

早些時候,對不起,如果我的英語不好如何將變量傳遞給codeigniter中的條件連接?

第一我有這樣

$data[code] = "xyz123"; 
$data[type] = "train"; 

和查詢變量i在這樣

$this->db->select('*'); 
$this->db->from('table1'); 
$this->db->join('table2', 'table2.id = table1.id'); 
$this->db->select('table3', 'table3.id = table1.id AND table1.code LIKE $data[code] AND table1.type LIKE $data[type]'); 

模型編寫但是當我嘗試,它不工作,我認爲語法AND和我寫的是錯誤的。請任何人知道解決方案?

謝謝你。

+0

使用' 「',而不是''''如」 table3.id = table1.id AND table1.code LIKE $ data [code] AND table1.type LIKE $ data [type]「'而不是'table3.id = table1.id AND table1.code LIKE $ data [code] AND table1.type LIKE $ data [type]'' – itachi

+0

plus,同時引用數組鍵,使用''''或'''。例如''data ['code']'或'$ data [「code」]' – itachi

+0

在常見的查詢中傳遞變量以像這樣查詢'「table3.id = $ data ['type']」'right?所以在積極的記錄我可以這樣寫? –

回答

1

嘗試CI之類的函數:

$this->db->like('type', $data['type']); 
$this->db->like('code', $data['code']); 
3

我想你需要嘗試這個辦法:

$this->db->select('table1.*,table2.*,table3.*'); 
$this->db->from('table1'); 
$this->db->join('table2', 'table2.id = table1.id'); 
$this->db->join('table3', 'table3.id = table1.id'); 
$this->db->like('table1.type', $data['type']); 
$this->db->like('table1.code', $data['code']); 
+0

爲downvote的原因,看到上面的評論。 – itachi

+0

@itachi現在看編輯 –

+0

刪除......... – itachi

0
$data["code"] = "xyz123"; 
$data["type"] = "train"; 

$this->db->select('*'); 
$this->db->from('table1'); 
$this->db->join('table2', 'table2.id = table1.id'); 
$this->db->select('table3', 'table3.id = table1.id AND table1.code LIKE '.$data["code"].' AND table1.type LIKE '.$data["type"].''); 
相關問題