我在我的網站中使用ajax搜索。用戶可以在家中搜索。我想讓用戶用他想要的關鍵字精確搜索。但我的問題是,我不知道用戶輸入了多少關鍵字可以搜索。 這是我的查詢:PHP MySqli多個關鍵字搜索
$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'嗎? –