[英]db->query LIKE statement not functioning correctly
I am using joomla and encounter a small issue.我正在使用 joomla 并遇到一个小问题。 In one of my db query I have a like statement as per below.
在我的数据库查询之一中,我有一个如下所示的类似语句。
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('a.*,b.category_name')
->from('#__carlist AS a')
->innerJoin('#__categories AS b ON b.id = a.category_id');
if ($name != '') {
$query->where("a.db_name like '%" . $name . "%'");
}
$db->setQuery($query);
$rows = $db->loadObjectList();
The issue is that when I do a search from my search box, the result is abit different from using normal sql.问题是,当我从搜索框中进行搜索时,结果与使用普通 sql 有点不同。
Where is wrong.哪里错了。 eg if I search for 'hello me' the system will return no result.
例如,如果我搜索“hello me”,系统将不会返回任何结果。 if I search for 'one' it will return result.
如果我搜索“一”,它将返回结果。 In the DB there is really 'hello me' in it.
在数据库中真的有“你好我”。 Whenever I search for a string two words or more, the result will not return although in the DB it exist.
每当我搜索两个单词或更多的字符串时,结果不会返回,尽管它存在于数据库中。
Does anyone know whats wrong with my coding?有谁知道我的编码有什么问题?
if your data is like that:如果你的数据是这样的:
a.db_name like '%hello me%' // in the end should be like that
you have to echo your query and see if it looks like that.你必须回显你的查询,看看它是否看起来像那样。 you'll have to make the query to look more like:
您必须使查询看起来更像:
Like '%hello%me%'
or split the two words to be或将两个词拆分为
Like '%hello%' or like '%me%'
you can also try with full text search您也可以尝试使用全文搜索
MATCH( a.db_name) AGAINST ('hello me' in BOOLEAN MODE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.