Connecting Tech Pros Worldwide Forums | Help | Site Map

asp/sql

colinod's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 182
#1: Jul 28 '09
I have a web page that searches 2 fields of a database, this works fine if all the words serched are in one field but does not work if the words are in seperate fields.
It searched names of mp3 files and also a field that conatins various words to describe it, so if you type in female west country into the search field and none of the filenames contain the word female it returns no results unless the three words are in the description field, i am sure this can be resolves in the sql statement which is generated by asp.

here is the code

Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. if InStr(session("recordsInCart"), ","&request.form("recordNum")) = 0 then 
  4.    session("recordsInCart") = session("recordsInCart") + request.form("recordNum") &","
  5. else 
  6.    'do nothing
  7. end if 
  8. %>
  9. <%
  10. Dim strSearch, myarray, strSQL, strSQLExtra 
  11. If Not Request.Form("search") = "" Then 
  12. session("search") = Request.Form("search") 
  13. session("choice") = Request.Form("choice") 
  14. session("queryterm") = session("queryterm")+" "+Request.Form("search")
  15. End If 
  16.  
  17. 'Loop is now in a function, so that we can feed it each field name. 
  18. Function addparams(fieldname,wordArray)  
  19. Dim tmp 
  20. tmp = "" 
  21.     For each item in wordArray 
  22.     tmp = tmp & " (" & fieldname & " Like '%" & item & "%') " & session("choice") & " " 
  23.     next 
  24.     tmp = left(tmp, len(tmp)-4) ' Chops off the last "AND " 
  25.     addparams = tmp 
  26. End Function 
  27.  
  28. 'Build the word array 
  29. myarray = split(session("search"), " ") 
  30.  
  31. 'Build the SQL  
  32. strSQL = "SELECT * FROM mp3 INNER JOIN celebs ON mp3.celebid = celebs.idnumber WHERE (" 
  33.  
  34. strSQL = strSQL & addparams("filename", myarray) ' change field one! 
  35.  
  36. strSQL = strSQL & ") OR (" 
  37.  
  38. strSQL = strSQL & addparams("mp3type", myarray) ' change field two! 
  39.  
  40. strSQL = strSQL & ")order by surname, firstname, filename;" 
  41. session("sqlset") = strSQL
  42.  
  43.   %>
i hope someone can help

jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: Jul 29 '09

re: asp/sql


There are a few possible solutions to this problem, but let me tell you there are specialists who make the kind of query you are looking for professionally.

The simplest solution I can think of is to add the filename in the keyword field, then you only have to search one field.

Jared
colinod's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 182
#3: Jul 30 '09

re: asp/sql


yes i thought of that but it was a lot of copying and pasting i have 3800 records, if you know a quick way of doing this in access any help would be appreciated
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#4: Jul 30 '09

re: asp/sql


Quote:

Originally Posted by colinod View Post

yes i thought of that but it was a lot of copying and pasting i have 3800 records, if you know a quick way of doing this in access any help would be appreciated

That shouldn't be a problem for someone who knows how to use ASP! Write a script that goes through the table one row at a time and makes the necessary change!

Jared
colinod's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 182
#5: Jul 30 '09

re: asp/sql


i did it with a update query in access thanks for your help
Reply