javascript - Search words in any order using JS -
i have code search typed words text box, typed word, search in web sql database , show result in html page.
in can search word is, using like.
(i.e)
select * tblname searchword %<typedword>%
if table has,
- hello doctor
- hi sir
- hello world
- welcome programmer
and user types "hello", shows me
**hello** doctor **hello** world
i need display result if user wrongly arranges words,
i.e if user types "world hello"
it not showing results. but, want show user
hello world
can please me?
so want , search using each of words entered, rather exact string? howabout this:
var yoursearchtext = 'world hello'; var searchterms = yoursearchtext.split(' '); var searchtermbits = []; for(var i=0; i<searchterms.length;i++) { searchtermbits.push("word %"+searchterms[i]+"%"); } var result = searchtermbits.join(" , "); var query = 'select * table '+result;
this give query like:
select * table word '%world%' , word '%hello%'
change , or if want match of search terms rather all.
Comments
Post a Comment