![]() |
Search using a few keywords
Hi all, how do i search my database using a few keywords? Say instead of the usual one keyword search,i want to search say 'cat,dog,mouse' instead of maybe 'cat' only. How do i do it? I understand there is a split function but how does it work?
at the moment i have these codes. I have 4 textboxes of inputting the keywords that will lead to the article. then i join them into one field name called 'keywords' inside my database. strKeyword1=Request("keyword1") strKeyword2=Request("keyword2") strKeyword3=Request("keyword3") strKeyword4=Request("keyword4") strKeywords=strKeyword1&","&strKeyword2&","&strKeyword3&","&strKeyword4 searchkeyword=Request.QueryString("keywords") sql="Select * from news where keywords='"&searchkeyword&"'" multiplekeywords=split(sql,"") RS.Open sql,Conn,3,3 i figure the problem is from the serachkeyword onwards. I can't get the logic of it - someone pls helpp !!!!!! |
I dont know much bout sql but back when I used mysql I would use OR.
"SELECT * FROM news WHERE keywords="keyword1" OR keywords="keywords2" OR.... I think thats how I did it. Im not sure, its ben a year since ive used mysql. |
thanks,guess i could only use that way. But say if i enter keywords into the search textbox using a comma as in 'cat,dog,mouse' it doesnt work? instead it doesnt give me any output at all. how do i implement the commas?
i tried your code..well it gave me this error : expected end of statement sql="select * from news where keywords="keyword1" or keywords="keyword2" or keywords="keyword3" or keywords="keyword4"" whats wrong? missing " or .. ? |
like I said I really dont know much, but replace the " " around the keywords with ' '. I think that will get it working.
wait a second, why are you up so late? Go to sleep and when you wake up someone smart will have answered your questions properly. |
It may be late where you are, but it is late morning in this part of the world. I wouldn't make any assumptions on his/her nightey-night bedttime. ;)
--EDIT.. ok, so YOU should be the one hittin' the hay. :D LOL |
well Im close to the forum time. Its 30 minutes ahead of me. Either way if he takes a nap im sure someone smart will come along while hes sleep. :)
Edit/reply: *Yawn* I am kinda sleepy but me and my cousin are competing to see who can go the longest without sleep. *Glares at cousin* heh, he wont last much longer. |
Hi all, looks like im back at this again. i've been stuck at this for a very long time,can't figure out how to do it. I've done a search, but it can only search using one keyword. I want to be able to search using one or more keywords, separated by a comma. How do i do that? The keywords will only be searched in two fields : Title and Description. Below is my code:
search=Request.form("search") searchstring=Split(Request.form("search"), ",") max=ubound(searchstring) for i=0 to max-1 word = searchstring(i) sqlsearch=sqlsearch & "title like '%" & word & "%' or descpt like '%" & word & "%'" if i <> max-1 then sqlsearch=sqlsearch & " or " end if next Response.Write "XX" & sqlsearch & "XX" <---- this is to print out and see please tlel me what's wrong,i can only use one word search .As in when i enter keywords like "haha,too" it only returns the entries with the keyword haha but not the "too". WHen i print out the sqlsearch, it turned out that the "too" did not go in ie the print out was like this : XXtitle like '%haha%' or descpt like '%haha%'XX HELP !!!!! |
| All times are GMT -5. The time now is 2:08 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC