|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
search box
I am relatively new to asp so still need help on it.
On my site I have a search that allows users to search for a specific job skill ie.cobol, asp etc... The problem is that at the moment the search can only search for what is exactly typed in the box eg. "ASP" this search works fine, "ASP, HTML" this doesnt because It searches for what is typed in. I have been told It is something to do with parsing and that this will allow me to search for multiple job skills using commas to split what is typed in. If any body has any ideas I will be very greatfull. Thanks Last edited by gintom : September 21st, 2003 at 05:24 AM. |
|
#2
|
||||
|
||||
|
What you need to do is to split all the "pieces" or individual keywords, and then string them together to make a "WHERE" statement that checks against each of the pieces. This is usually done with a boolean flag which indicates if you want to use "OR" or "AND" to separate the conditions (any of the words, or al of the words respectively).
I use a routine like: Code:
strSplit = split (TitVal) ' value to search for in title For i = 0 To UBound(strSplit) if (strSplit(i) <> "") and (strSplit(i) <> " ") Then sql_where = sql_where & " TitTxt like '%" & cln_txt(strSplit(i)) & "%' " & TitTip ' TitTxt is my title text field, and TitTip is the boolean value from the form, either AND or OR ' cln_txt is a function I use to trim beginning and end spaces, substitute odd characters, etc. End If Next 'i |
|
#3
|
|||
|
|||
|
Thanks for the example "OldJacques" but how do I extend it to search further arrays, just incase the user puts in 4 search words eg. cobol, html, asp, javascript?
This is the code that I have, I know that this is basic compared to what else I could do but, this is all I know at the moment. In the search I can retrieve the first search word but not the second, third..... Is there a way to extend the building of the SQL statement to include all the valid element from the Array but not using empty. Code:
<%
dim ArrayName
ArrayName = split(Request.form ("search"),",")
%>
<%
' Display Product Types
SQL = "SELECT * FROM jobs Where description Like " & "'%" & ArrayName(0) & "%'"
set Rs = Conn.Execute(SQL)
%>
|
|
#4
|
||||
|
||||
|
Quote:
|
|
#5
|
|||
|
|||
|
I have got the coding to work to begin the search for the elements in the search but the problem that I am having now is trying to actually put it into a SQL statement.
This code does the parsing side of it. This all works fine. Code:
<%
strSplit = split(Request.form ("search"),",") ' value to search for in title
Dim iNext
For i = 0 To UBound(strSplit)
if (strSplit(i) <> "") and (strSplit(i) <> " ") Then
if (i=0) then
Booltxt="WHERE "
Else
Booltxt="OR "
End If
sql_where = sql_where & Booltxt & " description like '%" & strSplit(i) & "%' "
' TitTxt is my title text field, and TitTip is the boolean value from the form, either AND or OR
' cln_txt is a function I use to trim beginning and end spaces, substitute odd characters, etc.
End If
Next 'i
Response.Write(sql_where & "<BR>")
%>
But the part I am having difficulties with is the SQL string (below) I am trying to put the parsing string where these are:********************** But not having much luck. Code:
<% ' Display Product Types SQL = "SELECT * FROM jobs ********************** " set Rs = Conn.Execute(SQL) Response.Write(SQL & "<BR>") %> Once again any help or ideas will be much appreciated. Tom |
|
#6
|
||||
|
||||
|
Maybe I don't understand, or maybe you need a short break, but the solution should be to use
Code:
SQL = "SELECT * FROM jobs " & sql_where what is: Response.Write(SQL & "<BR>") giving you? |
|
#7
|
|||
|
|||
|
Quote:
it is giving th following SELECT * FROM jobs (what ever is typed in here eg sql_where) |
|
#8
|
|||
|
|||
|
its work now mate thank you very much, perhaps I will go for that break now.
![]() |
|
#9
|
||||
|
||||
|
Sounds like you are putting it inside the quotes, like SQL = "SELECT * FROM jobs sql_where" instead of SQL = "SELECT * FROM jobs " & sql_where & " " or similar
|
|
#10
|
|||
|
|||
|
thats exactly what I was doing
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > search box |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|