带有通配符的Codeigniter LIKE(%) [英] Codeigniter LIKE with wildcard(%)
本文介绍了带有通配符的Codeigniter LIKE(%)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在codeigniter中有简单的数据库查询,但是我无法使用通配符进行搜索.这是我的代码:
I have simple database query in codeigniter, however I cannot get search to work with wildcard. This is my code:
$this->db->like('film.title',"%$query%");
$this->db->escape_like_str($query);
$res = $this->db->get('film');
如果我删除通配符(%),则搜索工作正常. $ query只是带有用户输入的字符串.感谢您的帮助.
If I remove wildcard(%) then search works fine. Also $query is just string with user input. Any help is appreciated.
推荐答案
$this->db->like()
自动添加%s并转义字符串.因此,您需要的只是
$this->db->like()
automatically adds the %s and escapes the string. So all you need is
$this->db->like('title', $query);
$res = $this->db->get('film');
See the CI documentation for reference: CI 2, CI 3, CI 4
这篇关于带有通配符的Codeigniter LIKE(%)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文