OutFront Forums
     Home    Register     Search      Help      Login    

Sponsors
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

 

Search using Multiple Keywords

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP, PHP, and Database >> Search using Multiple Keywords
Page: [1] 2   next >   >>
 
 
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
Search using Multiple Keywords - 1/7/2003 20:03:57   
Howdy All,

Does anybody know how to conduct an MS-Access search using a standard FP DRW form that has been dieted??? I' ve seen on many sites (including this one) where you can enter multiple keywords in a search... Anyone have any ideas on conducting a DRW or ASP Search using multiple keywords???
Thanks in Advance...
LLLuneeeee :)


_____________________________

rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: Search using Multiple Keywords - 1/7/2003 22:40:26   
quote:

...using a standard FP DRW form ...


IMO, that' s probably not the best place to start with that prob:). But if you must use a DRW, I would try to build the query outside the DRW and pass it as a variable. Maybe something like:

<%DIM myArray, myQuerystring

myArray = split(Request.Form(" keywords" )," " ) ' splitting on spaces
myQuerystring = " "

FOR i = 0 to (uBound(myArray)-1)
myQuerystring = myQuerystring & " ' " & myArray(i) & " ' ,"
NEXT

' don' t want a comma trailing the last one
myQuerystring = myQuerystring & " ' " & myArray(i) & " ' " %>

Then for your dieted DRW query, maybe something like:

fp_sQry=" SELECT * FROM myTable WHERE keyword IN (" & myQuerystring & " )"

Haven' t tested this at all (or checked for no entries or anything) but I think it may work. [:p] Hope it helps..

(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/7/2003 23:31:27   
rdouglass,

Thanks for your input. It sounds very interesting. I am going to give it a try and see what comes up. I' ll post the results when I get them.

THANKS :)
LLLuneeeeeeeeeeeeeeee

_____________________________


(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 4:07:52   
Hi LLL,

It is nice to see you again my friend.:)

Check this link, is this what you want?


http://www.fmhs.uaeu.ac.ae/immconf/country2.asp


Hisham

(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 5:34:31   
Hi LLL,

I tried rdouglas' code, when I try it from frontpage it works fine but give SQL error.

If you go now to this address from here, you will get an error or (i) being out of range. Maybe I put the code in the wrong place. Click here to see the error.

http://www.fmhs.uaeu.ac.ae/immconf/CountryASP.asp

Here is how my page looks in HTML view:
<form BOTID=" 0"  METHOD=" POST"  ACTION=" CountryASP.asp" >
  <table BORDER=" 0" >
    <tr>
      <td><b>Country</b></td>
      <td>
      <input TYPE=" TEXT"  NAME=" Country"  VALUE=" <%=Request(" Country" )%>"  size=" 20" ></td>
    </tr>
  </table>
  <p><br>
  <input TYPE=" Submit" ><input TYPE=" Reset" ><!--webbot bot=" SaveAsASP"  clientside suggestedext=" asp"  preview="  "  --></p>
  <p> </p>
</form>
<table width=" 100%"  border=" 1" >
  <thead>
    <tr>
      <td><b>CustomerID</b></td>
      <td><b>CompanyName</b></td>
      <td><b>ContactName</b></td>
      <td><b>ContactTitle</b></td>
      <td><b>Country</b></td>
    </tr>
  </thead>
  <tbody>

<!--#include file=" _fpclass/fpdblib.inc" -->
<%

DIM myArray, myQuerystring 

myArray = split(Request.Form(" Country" ),"  " ) ' splitting on spaces 
myQuerystring = " "  

FOR i = 0 to (uBound(myArray)-1) 
myQuerystring = myQuerystring & " ' "  & myArray(i) & " ' ,"  
NEXT 
myQuerystring = myQuerystring & " ' "  & myArray(i) & " ' " 

%>
<% if 0 then %>
<SCRIPT Language=" JavaScript" >
document.write(" <div style=' background: yellow; color: black;' >The Database Results component on this page is unable to display database content. The page must have a filename ending in ' .asp' , and the web must be hosted on a server that supports Active Server Pages.</div>" );
</SCRIPT>
<% end if %>
<%
fp_sQry=" SELECT * FROM Customers WHERE Country IN ("  & myQuerystring & " )" 
fp_sDefault=" Country=" 
fp_sNoRecords=" <tr><td colspan=5 align=left width=" " 100%" " >No records returned.</td></tr>" 


Best regards
Hisham


Best regards
Hisham

< Message edited by hhammash -- 1/9/2003 5:37:13 AM >

(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 13:55:10   
Hisham,

Hey what' s up??? I made it back to the forum about 10 days ago and hadn' t seen any posts from you. I figured you were swamped with work like me. Glad to hear from you. OutFront is not the same without Hisham crusing the posts!!!

http://www.fmhs.uaeu.ac.ae/immconf/country2.asp
Yes, this was what I was looknig for and it works nicely on the page. I will have to give it a try.

Right after I made this post I got temporarily sidetracked again with customer catastrophies and didn' t have the time to try rdouglass' idea. I was just coming back to get his info and give it a try when I saw your posts in my emailbox.

http://www.fmhs.uaeu.ac.ae/immconf/CountryASP.asp
I went to the temp page you made with the code in it. I saw the error that was generated. I have to check into it more closely.

Do you know how much time you saved me by testing the code out yourself??? That was GREAT!!! Thank you very much. I really appreciated that. You ARE the man!!! Thanks :)

I' m going to test the code you provided in your link also. If I can get the job done in FP, that would be quicker. I love ASP. But there are rules:

FP: Easier but less flexible and less techical.
ASP: Harder but more flexible and more technical.

Normally I prefer ASP. It' s always safer for me and I have more control over the results. But in this case FP may be the quicker, easier answer that gets me the results I need.

Whenever I make a post I aways get a response from rdouglass, you and/or Spooky. You guys are " Tops" ... And I appreciate it very much.

Thanks for taking the time to help me out.
Happy New Year...
Your Friend,
LLLuneeeeeeeeeeeee :)




_____________________________


(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 15:34:31   
Hisham,

Do you have an example like:
http://www.fmhs.uaeu.ac.ae/immconf/country2.asp

but with a edit-field instead of a combo-box???
Thanks,
LLLuneeeeeeeeeeeeeeeeeeeeeeeeeee:)


_____________________________


(in reply to Long Island Lune)
garyb

 

Posts: 208
From: North Clarendon Vermont USA
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 15:46:22   
Here is an excellent example of how to do multiple keyword search with the ability of the user to choose all words, any word or exact match...
http://www.asp101.com/forum/display_message.asp?mid=164055

(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 20:47:22   
rdouglas,

My luck seems to be bad. It didn' t work. I tried numerous variations with no success. Thanks for your input.

garyb,
That' s a heavy-duty piece of code. A little confusing too. But I will look into it and see if I can adapt it. Thanks.

LLLuneeeeeeeeee :)


_____________________________


(in reply to Long Island Lune)
Spooky

 

Posts: 26723
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 21:08:23   
Try this?

<%DIM myArray, myQuerystring 

myArray = split(Request.Form(" keywords" ),"  " ) ' splitting on spaces 
myQuerystring = " "  

FOR i = 0 to (uBound(myArray)-1) 
myQuerystring = myQuerystring & " ' "  & myArray(i) & " ' ,"  
NEXT 

' don' t want a comma trailing the last one 
myQuerystring = myQuerystring & " ' "  & myArray(uBound(myArray)) & " ' " %> 


_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

Sp:)ky


(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 22:14:38   
Spooky,

I got it to work with no errors BUT it returns nothing.

Search Example:
Somebody enters this in the edit-field:

leather blue black

We see three words here that they want to search by.
My question is:

Is the query searching for ANY of these three words or is it searching for these words IN there original inputted order?

In other words:

Will it return: leather black?

Here is the code. I changed it around to suit my variables:

<%
Dim keyw
Dim myquery
DIM myQuerystring
keyw = split(Request.Form(" Keyword" )," " )
myQuerystring = " "
FOR i = 0 to (uBound(keyw)-1)
myQuerystring = myQuerystring & " ' " & keyw(i) & " ' " -(I REMOVED THE COMMAS)
NEXT
myQuerystring = myQuerystring & " ' " & keyw(uBound(keyw)) & " ' "
%>


Then the query looks like this:

<%
myquery = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND (ItemName IN (" & myQuerystring &" ) Or Description IN (" & myQuerystring &" ))) ORDER BY EQPSpecialPrice ASC"
%>


It does not generate any errors but also does not return any values.

NOTE: I removed the commas. When the commas were present I got an error. When I removed them it did not generate an error.

Any ideas???
Thanks
LLLuneeeeeeeeeeee :)


_____________________________


(in reply to Long Island Lune)
Spooky

 

Posts: 26723
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 22:55:00   
It depends what sort of results you are requiring.
I think you need a " LIKE" search?
" IN" looks for that one term, it does not perform a " contains" query

This code will check the output of the SQL:
<%
myquery = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND (ItemName IN (" & myQuerystring &" ) Or Description IN (" & myQuerystring &" ))) ORDER BY EQPSpecialPrice ASC"

response.write myquery
response.end
%>

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

Sp:)ky


(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/9/2003 23:30:55   
Spooky,

Yes, I have an output monitor on the site right now that shows what the actual query looks like once assembled.

I will try the " Like" variation. I played with it a little already but will concentrate more on it.

Thanks :)
LLLuneeeeeeeeeeeeeeeeeeeeeyyy !!!
That' s the turth!!! :)



_____________________________


(in reply to Long Island Lune)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: Search using Multiple Keywords - 1/10/2003 9:44:50   
Sorry ' bout not being around for a coupla' days - been quite busy...

Also sorry about the " IN" stuff - I' ve never had much luck with it and I was taking a shot at it. However I have been sucessful using the LIKE method similar to this:

<%DIM myArray, myQuerystring

myArray = split(Request.Form(" keywords" )," " ) ' splitting on spaces

myQuerystring = " (keyword LIKE ' %" & trim(myArray(0)) & " %' )"

IF uBound(myArray) > 0 THEN

FOR i = 1 to uBound(myArray)
myQuerystring = myQuerystring & " AND (keyword LIKE ' %" & trim(myArray(i)) & " %' )"
NEXT

END IF%>

Then use something like this in your DRW:

fp_sQry=" SELECT * FROM myTable WHERE " & myQuerystring

Again, the ' brute force' method but does seem to always work...[:' (] Hope it helps...

(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/10/2003 11:55:50   
Hi rdouglas,

Your first code (with the IN) almost worked. Please take a look at these cases and judge:

I pasted your code above the fp_sQry, saved the page then clicked the browse button. It showed the textbox and a yellow block of sql error. I typed in the textbox " I want to look for customers in USA and France" then pressed submit. It gave me results in both USA and France.

If I press refresh before I type a text I get a " The page cannot be displayed ...erro" and on that page I get that (i) is out of range.

If I put the page as a link on the forum I get the Page cannot be displayed.

Why did the code work the first time and will always work if I don' t press the refresh button to get rid of the sql error?

Thanks
Hisham

(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/10/2003 11:57:03   
rdouglass,

Looks great. I' m going to attempt it today. I' ll post later with the results.
Thanks :)
LLL


_____________________________


(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/11/2003 13:25:45   
Hi LLL,

So, what happened? did the code work?

I checked rdouglas' code again and again ( I mean the first one which searches with IN) it is almost working fine except it is saying the the (i) is out of range.

Best regards
Hisham

(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/11/2003 18:46:23   
Hisham,

Oh yeah - I have been playing and playing with this problem. I followed Spooky' s advice and went to " Like" . rdouglass' second version is the one I am testing right now. I almost got it. I can get the code to assmble my SQL string correctly (syntactically) but it will not return anything. If I can' t solve it in another day I' m going to post my latest code and see if anyone knows what is wrong.

Like I said, I got the code to assemble the correct SQL string but it always retuns nothing. Working towards a headache...

Want to see the code now???

Thanks Hisham,
see ya,
LLLuneeeeeeeeeeeeeeeeeeeeeeeeeeeYYYYY :)





_____________________________


(in reply to Long Island Lune)
Spooky

 

Posts: 26723
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Search using Multiple Keywords - 1/11/2003 19:02:07   
See the SQL string?

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

Sp:)ky


(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/11/2003 19:10:38   
Hisham, Rdouglass and Spooky,

Of cousre I' ve changed the code around a little to suit my needs. Here is the point I' m up to so far:


<%
Dim Keyw
Dim myquery
Dim myQuerystring
Keyw = split(Request.Form(" Keyword" )," " )
myQuerystring = " (ItemName Like ' %" & trim(Keyw(0)) & " %' "
myQuerystring = myQuerystring & " Or Description Like ' %" & trim(Keyw(0)) & " %' )"
if uBound(Keyw) > 0 Then
for i = 1 to uBound(Keyw)
myQuerystring = myQuerystring & " OR (ItemName Like ' %" & trim(Keyw(i)) & " %' )"
myQuerystring = myQuerystring & " OR (Description Like ' %" & trim(Keyw(i)) & " %' )"
next
end if
Keyw = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND "
Keyw = Keyw + myQuerystring
Keyw = Keyw + " ) ORDER BY EQPSpecialPrice ASC"
myquery = keyw
response.write (myquery & " <BR>" )
%>

Here is the string it assembles:

ONE Search word:

SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND (ItemName Like ' %Leather%' Or Description Like ' %Leather%' )) ORDER BY EQPSpecialPrice ASC

TWO or MORE words:

SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND (ItemName Like ' %Leather%' Or Description Like ' %Leather%' ) OR (ItemName Like ' %Black%' ) OR (Description Like ' %Black%' )) ORDER BY EQPSpecialPrice ASC

Pretty cool huh??? I just tested it. It works - too a degree!!! The problem seems to be that the " ProductType" is being ignored in the search. It' s returning many things that are outside the ProductType. Is the search TOO COMPLEX? Should I use more parenthesis??? Anybody see what is wrong?

Thanks MUCH.
LLLuneeeeeeeeeeeeeeeeeee :)




_____________________________


(in reply to Long Island Lune)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: Search using Multiple Keywords - 1/12/2003 15:03:08   
I think I might see what' s happening. AND' s & OR' s are read (and executed) left to right, things done in parens first. So what I see happening is something like:

1 AND 2 OR 3

EDIT: Which is the same thing as (1 AND 2) OR 3!

What I think you want is:

1 AND (2 OR 3)

Do I see this correctly? If so, try these lines:

<%
Dim Keyw
Dim myquery
Dim myQuerystring
Keyw = split(Request.Form(" Keyword" )," " )
myQuerystring = " (ItemName Like ' %" & trim(Keyw(0)) & " %' "
myQuerystring = myQuerystring & " Or Description Like ' %" & trim(Keyw(0)) & " %' )"
if uBound(Keyw) > 0 Then
for i = 1 to uBound(Keyw)
myQuerystring = myQuerystring & " OR (ItemName Like ' %" & trim(Keyw(i)) & " %' )"
myQuerystring = myQuerystring & " OR (Description Like ' %" & trim(Keyw(i)) & " %' )"
next
end if
Keyw = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND ("
Keyw = Keyw + myQuerystring
Keyw = Keyw + " )) ORDER BY EQPSpecialPrice ASC"
myquery = keyw
response.write (myquery & " <BR>" )
%>

See the extra parens? I hope it helps...

< Message edited by rdouglass -- 1/12/2003 3:04:21 PM >

(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/13/2003 5:29:49   
Hi rdouglas,

Would you please check your first code which create an array then in sql search as (where fieldname in (" & mystring & " ). It is almost working and it is searching fine at the first load.

If I press refresh the page can not be display and the error is (i) is out of range.

It is important because IN difference from Like in the results.

Thanks
Hisham

(in reply to Long Island Lune)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: Search using Multiple Keywords - 1/13/2003 8:13:28   
Hisham,

quote:

about the " IN" stuff - I' ve never had much luck with it and I was taking a shot at it


What specifically are you having a problem with?

EDIT: If I had to take a guess right now, I' d try this:

<%DIM myArray, myQuerystring

myArray = split(Request.Form(" keywords" )," " ) ' splitting on spaces
myQuerystring = " "

FOR i = 0 to (uBound(myArray)-1)
myQuerystring = myQuerystring & " ' " & myArray(i) & " ' ,"
NEXT

' don' t want a comma trailing the last one
myQuerystring = myQuerystring & " ' " & myArray(ubound(myArray)) & " ' " %>

Haven' t tested - just a guess...

< Message edited by rdouglass -- 1/13/2003 8:17:40 AM >

(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/13/2003 8:15:33   
Thanks rdougls


Hisham

(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/13/2003 12:55:26   
rdouglass,

Sorry - side tracked again!!! Story of my life. Got your response and I think you may have a point there. Presedence order between OR and AND just might be the problem. I' ll work on it an post the final results.
Today.
Thanks
LLLuneeeeeeeeeeeeee :)

_____________________________


(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/13/2003 14:53:46   
rdouglass,

I think we might have a WINNER!!! I performed two tests and it seems to work. But I have to do some extensive testing to be sure that it is right. The ProductType is being considered again in the search.

HOMERUN so far... I' ll do a final post once I am sure.

THANKS :) :) :)
Luneeeeeeeeeeeeeeeeee

_____________________________


(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/15/2003 12:44:32   
rdouglass,

After two days of putting this query through the ringer, it seems to work perfectly. Alas I think I can put this problem behind me now. Thanks for all your help.

Special Thanks to:
rdouglass
Hammash
Spooky
Garyb

:):):)

_____________________________


(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/16/2003 2:11:38   
Hi rdouglas,

quote:

What specifically are you having a problem with?

EDIT: If I had to take a guess right now, I' d try this:

<%DIM myArray, myQuerystring

myArray = split(Request.Form(" keywords" )," " ) ' splitting on spaces
myQuerystring = " "
.....etc


I tried something with your last modified code using IN with the Where statement.

What I did was put the form on page alone, then created another ASP page with the dieted DRW and added your code before the DRW. It worked fine. The problem occurs when you put the form, your code and the dieted DRW on the same page.

Why do you think this happens.

On separate pages they are working perfectly.

Best regards
Hisham

(in reply to Long Island Lune)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: Search using Multiple Keywords - 1/16/2003 2:19:21   
Hi LLL,

Glad it worked.

If you are interested, I would like to inform you that the code also worked using " WHERE IN" .

What to do is put the search form on a page, then create another page for the DRW, diet it, put the last code posted by rdouglas for using " IN" . Then post the form to the DRW page. It works perfectly.

Would you please post your successful page? Just the code and the SQL statement?

Thanks a lot LLL
Hisham

(in reply to Long Island Lune)
Long Island Lune

 

Posts: 2340
Joined: 6/8/2002
From: New York
Status: offline

 
RE: Search using Multiple Keywords - 1/16/2003 13:31:09   
Hisham,

Here is the main code for the SQL Query. In this final version, I had to add one more search option.

From pervious posts I was concerned with:
ProductType
ItemName
Description


The final version added one more:
Subcategory

So now it searches through 4 different fields.

I had to put entry-value-checking incase someone did not fill in a subcategory or enter keywords.

The scenario had to be:
Was a subcategory picked? Yes/No
Was a keyword entered? Yes/No
Was keywordS entered? Yes/No

The SQL could only be built after I knew the answers to these questions. So this is why you see many conditionals checking for the contents of variables: SubC and Keyw. Hope that helps make this routine understandable.


<%
Dim Keyw
Dim SubC
Dim myquery
Dim myQuerystring
SubC = Request.form(" SubCategory" )
Keyw = Request.Form(" Keyword" )
if (Keyw = " " Or Keyw = " " ) Then
if (SubC = " " Or SubC = " " ) Then
Keyw = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' )"
else
Keyw = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND SubCategory= ' ::SubCategory::' )"
end if
else
Keyw = split(Request.Form(" Keyword" )," " )
myQuerystring = " (ItemName Like ' %" & trim(Keyw(0)) & " %' "
myQuerystring = myQuerystring & " Or Description Like ' %" & trim(Keyw(0)) & " %' )"
if uBound(Keyw) > 0 Then
for i = 1 to uBound(Keyw)
myQuerystring = myQuerystring & " OR (ItemName Like ' %" & trim(Keyw(i)) & " %' )"
myQuerystring = myQuerystring & " OR (Description Like ' %" & trim(Keyw(i)) & " %' )"
next
end if
if (SubC = " " OR SubC = " " ) Then
Keyw = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' And ("
else
Keyw = " SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' And SubCategory= ' ::SubCategory::' AND ("
end if
Keyw = Keyw + myQuerystring
Keyw = Keyw + " )) ORDER BY EQPSpecialPrice ASC"
end if
myquery = Keyw
%>


Here are some smaples of the queries it produces:

NO Subcategory or keywodds entered:
SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' ) ORDER BY EQPSpecialPrice ASC

Subcategory entered and no keywords entered:
SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' AND SubCategory= ' ::SubCategory::' ) ORDER BY EQPSpecialPrice ASC

No Subcategory and ONE Keyword entered:
SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' And ((ItemName Like ' %Leather%' Or Description Like ' %Leather%' ))) ORDER BY EQPSpecialPrice ASC

Subcategory and ONE Keyword entered:
SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' And SubCategory= ' ::SubCategory::' AND ((ItemName Like ' %Leather%' Or Description Like ' %Leather%' ))) ORDER BY EQPSpecialPrice ASC

No Subcategory and 3 Keywords:
SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' And ((ItemName Like ' %Leather%' Or Description Like ' %Leather%' ) OR (ItemName Like ' %Black%' ) OR (Description Like ' %Black%' ) OR (ItemName Like ' %Strap%' ) OR (Description Like ' %Strap%' ))) ORDER BY EQPSpecialPrice ASC

And Finally....

Subcategory entered and 3 Keywords:
SELECT * FROM SpecialsDatabase WHERE (ProductType= ' ::ProductType::' And SubCategory= ' ::SubCategory::' AND ((ItemName Like ' %Leather%' Or Description Like ' %Leather%' ) OR (ItemName Like ' %Black%' ) OR (Description Like ' %Black%' ) OR (ItemName Like ' %Strap%' ) OR (Description Like ' %Strap%' ))) ORDER BY EQPSpecialPrice ASC

This ASP routine covers all the possiblities and correctly assembles the proper SQL Query to suit all the possible needs of the user. I think it is great. There' s nothing like having it automatically assemble the correct SQL Query for you.

:):):):):)
LLLuneeeeeeeeeeeeeeeeeeeeeeeeeeYYY





_____________________________


(in reply to Long Island Lune)
Page:   [1] 2   next >   >>

All Forums >> Web Development >> ASP, PHP, and Database >> Search using Multiple Keywords
Page: [1] 2   next >   >>
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts