Wrox Programmer Forums
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 3rd, 2008, 10:06 AM
Authorized User
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in searching multiple keywords

hi, good day.
i have some problem in doing the searching multiple keywords function.

in my layout i have a textbox,user can insert many keywords with the comma separator between each keywords. and then the search function will go to search 3 field in table A, let say field 1 ,field 2 and field 3 see whether got match the keywords or not.
table A
ID |field 1 | field 2 | field 3
1 |air conditioner |air conditioner,free| air conditioner
2 | chair | chair,furniture | chair,furniture
3 | hair | hair,human,body | hair,human,body
4 | dog | animal,dog | animal,dog
5 | cat | animal,cat | animal,cat

ok. let say i insert keywords such as --> " AIR,DOG,Animal " in the textbox and search it.
so based on the records from my table. it should query out the records : which ID = 1,4,5(Air Conditioner,Dog and cat)
it should not display the result for Chair OR hair even these two words combine with AIR tis word (Ch +Air) & (H +Air).
the record Cat will show out becoz in the field 2 the "Animal" keywords is matched. therefore it will show out.

so the final result it will display Air conditioner, dog and cat

do u all get wat i mean?
i hope can get some response from u all soon. i need some help on coding.plz help.thanx alot.

P/s : i m using ASP with MS SQL Server 2005

Old April 3rd, 2008, 04:48 PM
Friend of Wrox
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41

Do you need help with the th split function to generate the SQL or help with the SQL? I read your question 50/50 each way...

;;;it should not display the result for Chair OR hair even these two words combine with AIR tis word (Ch +Air) & (H +Air).

It will if they are stored in TEXT data type fields. you can not use the equal operator for TEXT fields, you have to use the LIKE operator. What data types are the fields you need to query?

NOTE : 'animal,dog' is a value in your DB? You do realize this is one string? therefore a query which uses the = operator will not pick up 'animal' or 'dog' however the LIKE operator will. You would have to use the LIKE operator to pick up either of these two words however using the LIKE operator, if someone searches for 'ani' it would return the record 4 and 5. Understand???

Wind is your friend
Old April 3rd, 2008, 08:12 PM
Authorized User
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts

halo there..tis is the code and sql i have wrote. when i taip in keyword --> "a" it can search all the recordset which combine with "a" tis alphabet.i duno how to make it match in my case.
plz help


Dim selCrit,arrSearch
selCrit = "Or"

strInput=Replace(strInput,","," ")
Do While InStr(1, strInput, " ")
strInput = Replace(strInput, " ", " ")

arrSearch = split(strInput," ")
strName = join(arrSearch, "%') " & selCrit & " (FileTitle LIKE '%")
strImgKeyword = join(arrSearch, "%') " & selCrit & " (FileTag LIKE '%")
strphotographer= join(arrSearch, "%') " & selCrit & " (FileAuthor LIKE '%")

sqlImage = "Select * From TBL_MediaFiles"
sqlImage = sqlImage & " WHERE SellStatus ='2' AND Published='Y'"
sqlImage = sqlImage & " AND ((FileTag LIKE '%" & strImgKeyword& "%')"
sqlImage = sqlImage & " OR(FileTitle LIKE '%" & strName & "%')"
sqlImage = sqlImage & " OR(FileAuthor LIKE '%" & strphotographer & "%'))"

rsImage.Open sqlImage,objConn


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching Multiple Columns in Acess JezLisle Access 1 April 24th, 2008 11:37 AM
Searching multiple tables melkin Classic ASP Databases 0 March 10th, 2008 11:48 AM
sql: search multiple keywords for one image. kumiko SQL Server ASP 0 January 9th, 2008 03:03 AM
Searching Multiple Sheets for Data? Bill_L Excel VBA 2 June 20th, 2007 09:14 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.