【发布时间】:2018-02-27 09:39:51
【问题描述】:
function _searchProductByName($name = "") {
$query = $this->db
->select("S.*,CC.id as catId, CC.name as CatName")
->from("categories as S")
->join("categories as C",'C.id=S.parentid','LEFT')
->join("categories as CC",'CC.id=C.parentid','LEFT')
->where("S.order", 2)
->like("S.name", $name, 'both')
->order_by("S.name", 'asc')
//->order_by('locate('.$name.', S.name) asc, S.name asc')
->get();
return $query && $query->num_rows() ? $query->result() : [];
}
当我的关键字是 lap 它给出了结果:
{
"status": true,
"response": [
{
"id": "834",
"parentid": "46",
"name": "Collapsible Wardrobes",
"order": "2",
"hasChild": "0",
"icon": null,
"created": "2018-01-15 15:01:45",
"catId": "5",
"CatName": "Home Furniture, Decor , Pets"
},
{
"id": "936",
"parentid": "51",
"name": "Laptop Desks",
"order": "2",
"hasChild": "0",
"icon": null,
"created": "2018-01-15 15:01:45",
"catId": "5",
"CatName": "Home Furniture, Decor , Pets"
},
{
"id": "936",
"parentid": "51",
"name": "mobile latptop",
"order": "2",
"hasChild": "0",
"icon": null,
"created": "2018-01-15 15:01:45",
"catId": "5",
"CatName": "Home Furniture, Decor , Pets"
}
]
}
当我使用 after in place 或两者时,它只给出 Laptop Desks 结果,但当我搜索 lap 时我需要它给我结果。
笔记本电脑和移动笔记本电脑
第一个数据是 Collapsible Wardrobes,其中包含 lap,但它在可折叠之间,我不需要我如何得到这个?
【问题讨论】:
-
您可以在名称前后添加 % 以允许部分匹配。爱荷华州,
'%'.$name.'%' -
@SloanThrasher 我正在使用上面的 both 与您所说的相同。但我需要上面提到的
-
我不明白你在问什么,尤其是这一行。
when i use after in place or both it gives only Laptop Desks result but i need when i search for lap it gives me result.- 你能澄清一下你的意思吗? -
@Cashbee ->like("S.name", $name, 'both') 当我在给出结果名称后使用时代替两者 - 仅限笔记本电脑桌。但是当我搜索 lap 时,我还需要笔记本电脑桌和移动笔记本电脑。
-
好吧,这是预期的行为。所以我猜你想要的是使用
both,但从你的结果中删除“可折叠衣柜”?
标签: php mysql sql codeigniter activerecord