【发布时间】:2015-09-15 11:26:59
【问题描述】:
我在我的网站中使用 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 个关键字而不是更多时。
【问题讨论】:
-
你不应该使用 MySQL
OR而不是AND?