Database Searches in ASP

They have: 135 posts

Joined: Apr 2000

I want my users to be able to enter one or more search words, then I come back with a list of database entries containing those words. A one word search, of course, is easy, but I'd like the ability to not only accept multiple words, but also have a radio button for ANDing or ORing the search words.

Does anyone know where I could find such a code fragment? Surely this is a common thing -- they even have this functionality in their site search at asp101.com, but I couldn't find any code samples there!

------------------
http://www.RewardsLookup.com

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

KLWong,

You'll have to setup multiple SQL statements and then use If statements to determine your search.

I don't have time to write the code snippet but I'll try to explain. There are probably many ways to do this, but this is the first one that comes to my mind.

I would HTMLEncode the search phrase, then using the InStr and Mid functions I would search for spaces and separate all the search words into their own strings.

Then depending on what option button they selected (and/or) you can do the select statement.

If you're familiar with the InStr and Mid functions then this should be no problem for you. The challenge will be doing it in a efficient manner, using loops to get the search words, and not manually coding for each separate word.

Hope this helps.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.