CodeIgniter Active Record 'like'忽略 'where' [英] CodeIgniter Active Record 'like' ignoring 'where'

查看:50
本文介绍了CodeIgniter Active Record 'like'忽略 'where'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用like 进行一个非常简单的搜索并可以选择省略选项,但是我发现like 语句使查询忽略where 语句

riting a very simple search using like and have an option to omit options, however I find the like statement is making query ignore the where statement

$this->db->like('LOWER(location) OR LOWER(name)', strtolower($term));
$this->db->where('stage', 1);
$this->db->order_by("name", "asc"); 
$query = $this->db->get($this->user_table);
return $query->result();

上面使用 $term = "dublin" 生成的示例;

Example of what the above produces with $term = "dublin";

SELECT * FROM (`users`) WHERE `stage` = 1 AND LOWER(location) OR LOWER(name) LIKE '%dublin%' ORDER BY `name` asc"

它仍然返回 'stage' 不等于 1 的行.

It still returns rows where 'stage' is not equal to 1.

有什么想法吗?谢谢!

推荐答案

$term = strtolower($term);
$this->db->where("(LOWER(location) LIKE '%{$term}%' OR LOWER(name) LIKE '%{$term}%')");

这篇关于CodeIgniter Active Record 'like'忽略 'where'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆