发布于2023-01-19 16:48 阅读(984) 评论(0) 点赞(11) 收藏(0)
I use ajax search in my site. The user can search through homes. I want to enable user to do an exact search with exactly the keywords he wants. But the my problem is I don't know from what the user types how many keywords I can search. This is my query:
$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]%'";
it works but when user only types 3 keywords and no more.
use OR instead of AND
$query1 = "j.category_name like '%$newKeyword[0]%' OR f.type_name like '%$newKeyword[1]%' OR g.city like '%$newKeyword[2]%'";
I hope it will help you.
作者:黑洞官方问答小能手
链接:http://www.phpheidong.com/blog/article/476828/0360fe6afa87f88aee58/
来源:php黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 php黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-4
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!