我在我的站点中使用 ajax 搜索。用户可以搜索房屋。我想让用户能够使用他想要的关键字进行精确搜索。但我的问题是我不知道从用户输入的内容中我可以搜索多少关键字。 这是我的查询:
$query = "Select a.*,c.name as agent_name,d.country_name,e.state_name,g.city from #__osrs_properties as a"
." inner join #__osrs_agents as c on c.id = a.agent_id"
." inner join #__osrs_types as f on f.id = a.pro_type"
." inner join #__osrs_categories as j on j.id = a.category_id"
." inner join #__osrs_countries as d on d.id = a.country"
." inner join #__osrs_states as e on e.id = a.state"
." inner join #__osrs_cities as g on g.id = a.city"
." where a.approved = '1' and a.published = '1' and a.category_id = '$category->id' and (";
//
$newKeyword = explode(" ",$keyword);
$query1="j.category_name like '%$newKeyword[0]%' and f.type_name like '%$newKeyword[1]%' and g.city like '%$newKeyword[2]%'";
它可以工作,但是当用户只输入 3 个关键字时就可以了。
最佳答案
用 OR 代替 AND
$query1 = "j.category_name like '%$newKeyword[0]%' OR f.type_name like '%$newKeyword[1]%' OR g.city like '%$newKeyword[2]%'";
希望对您有所帮助。
关于PHP MySqli 多关键词搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32584839/