codeIgniter活动记录“像'忽略',其中' [英] CodeIgniter Active Record 'like' ignoring 'where'

查看:99
本文介绍了codeIgniter活动记录“像'忽略',其中'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

riting一个非常简单的搜索使用像,并有一个选项,忽略选项,但是我发现类似语句使查询忽略了where语句

  $这个 - > DB->像(LOWER(位置)或降低(名),用strtolower($期));
$这个 - > DB-化合物其中('舞台',1);
$这个 - > DB-> ORDER_BY(名,ASC);
$查询= $这个 - > DB->获得($这个 - > USER_TABLE);
返回$查询 - >的结果();
 

什么上面产生具有$长期=都柏林示例;

  SELECT * FROM(`雇员`)其中`stage` = 1和下部(位置)或降低(名称)LIKE'%都柏林%'ORDER BY`name` ASC
 

它仍然返回的行'阶段'不等于1。

任何想法?谢谢!

解决方案

  $长期=用strtolower($期);
$这个 - > DB-化合物其中((LOWER(位置)LIKE'%{$词}%或更低(名称)LIKE'%{$词}%'));
 

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();

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"

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

Any ideas? Thank you!

解决方案

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

这篇关于codeIgniter活动记录“像'忽略',其中'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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