我在DB中搜索一个关键字,它是Bootjack Fire and Rescue Foundation,因为单词后面只有一个空格,我的查询是
WHERE `title` LIKE '%Bootjack Fire and Rescue Foundation%'为什么搜索标题中的and关键字后面有两个空格,就像您在查询中看到的那样?
添加查询
$keyword = 'Bootjack Fire and Rescue Foundation';
$this->db->select('stores.id,store_title,store_category_id,store_sub_category_id,store_sub_category_type_id,sub_category_fourth,store_link');
$this->db->from('stores');
$this->db->join('users','users.id=stores.user_id');
$this->db->join('store_category','stores.store_category_id=store_category.id');
$where="`store_title` LIKE '%".$keyword."%'";
$this->db->where($where);
$this->db->where('store_status', 1);
$this->db->where('store_type', 2);
$this->db->where('store_category.status', 1);
$this->db->order_by('store_title','ASC');
$this->db->order_by('store_category_id');发布于 2016-07-19 10:38:48
您可以将多个空间转换为一个,然后使用相同的like子句。
$where="replace(replace(replace(store_title,' ','<>'),'><',''),'<>',' ') LIKE '% replace(replace(replace(".$keyword".,' ','<>'),'><',''),'<>',' ') %'";考虑到<和>符号不会出现在该列值中,否则需要使用其他符号。我已经在SQL-SERVER中使用了-SERVER也应该在Mysql中工作.。
您可以删除php中的多个空格,如下所示..。
$keyword=preg_replace('/\s+/', ' ',$keyword);然后使用简单的sql作为..。
$where="store_title LIKE '% ".$keyword" %'";发布于 2016-07-19 10:44:00
我认为在查询中是不可能的。
您可以转换关键字来修复任何错误的数据。
希望它能帮到你。
https://stackoverflow.com/questions/38455939
复制相似问题