[英]Adding a substring in a CodeIgniter Where Clause
是否可以在活動查詢中添加子字符串?
當我用純sql將其寫出時,我有這個示例可以工作。 但是,當我在CI中的活動查詢中編寫它時,結果不會顯示。 我想知道是否有人可以幫助驗證這是否正確。
$this->db->distinct();
$this->db->select('user_table.id','user_table.first_name','user_table.last_name','user_table.email','user_table.created_on');
$this->db->from($this->user_table);
$this->db->join($this->account_items_table,'user_accounts.id = account_items.user_id','LEFT');
$this->db->where('SUBSTRING(account_items.key,1,2)',$input);
CI可能在表達式周圍添加反引號,並在where()
中將第三個參數傳遞為false
$this->db->where('SUBSTRING(account_items.key,1,2)',$input,false);
這對我來說很好:
$this->db->where('SUBSTRING(title, 1, 1)=','H');
$query = $this->db->get('news');
print $this->db->last_query();
我可以看到的唯一區別是我包含了=運算符。
如您所見,它將返回名為“ Hello”的文章: https : //mi-linux.wlv.ac.uk/~in9352/codeigniter3/
SQL語句為:SELECT * FROM news
WHERE SUBSTRING(title,1,1)='H'
根據建議,您應該使用
print $this->db->last_query();
看看您的SQL是什么...就我而言,它允許發現缺少的=運算符...調試總是很有用的!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.