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,

  1. hello doctor
  2. hi sir
  3. hello world
  4. 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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -