jakykong
10-25-2003, 10:30 PM
okay, so i am using the following script(asp) to search a database. the database has a table named search wherein there are the columns title, url, keywords, and description. i am searching keywords, but the script will not return results if the user enters more than 1 keyword to search. does anyone have an idea of how to make asp split the search terms the user gives and then search each one to return the results?
<% Option Explicit %>
<html>
<head>
<title>Search results for <%= request.form("searchit") %></title>
</head>
<body bgcolor=#ff0000>
<table width=300>
<% Dim sql
Dim oRS
Dim oConn, sConnString
dim getform
dim numrecs, numwrds, num, nexter
dim separatewords(100)
set getform=request.form("searchit")
Set oConn = Server.CreateObject("ADODB.Connection")
sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("\jakykong\db\db1.mdb") & ";"
oConn.Open(sConnString)
sql = "select * from search WHERE keywords LIKE '%" & getform & "%'"
Set oRS = oConn.Execute(sql)
Do While Not oRS.EOF
response.write("<tr>")
response.write("<a href='" & oRS("url") & "'>" & oRS("title") & "</a>")
response.write("<tr>" & oRS("description"))
response.write("<br><br>")
oRS.MoveNext
numrecs=numrecs+1
Loop
if numrecs=0 then
response.write("No results")
else
response.write("Total found: " & numrecs)
end if
oRS.Close
oConn.Close
Set oRS = Nothing
Set oConn = Nothing
%>
</table>
</body>
</html>
like always, any and all help is greatly appreciated.
P.S. if you would like to test it out, you can go to http://www.jakykong.net.tf/codebank/earchit.asp (http://jakykong.net.tf/codebank/searchit.asp). this is the page that is pure html and has the form that the user inputs the search terms.
<% Option Explicit %>
<html>
<head>
<title>Search results for <%= request.form("searchit") %></title>
</head>
<body bgcolor=#ff0000>
<table width=300>
<% Dim sql
Dim oRS
Dim oConn, sConnString
dim getform
dim numrecs, numwrds, num, nexter
dim separatewords(100)
set getform=request.form("searchit")
Set oConn = Server.CreateObject("ADODB.Connection")
sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("\jakykong\db\db1.mdb") & ";"
oConn.Open(sConnString)
sql = "select * from search WHERE keywords LIKE '%" & getform & "%'"
Set oRS = oConn.Execute(sql)
Do While Not oRS.EOF
response.write("<tr>")
response.write("<a href='" & oRS("url") & "'>" & oRS("title") & "</a>")
response.write("<tr>" & oRS("description"))
response.write("<br><br>")
oRS.MoveNext
numrecs=numrecs+1
Loop
if numrecs=0 then
response.write("No results")
else
response.write("Total found: " & numrecs)
end if
oRS.Close
oConn.Close
Set oRS = Nothing
Set oConn = Nothing
%>
</table>
</body>
</html>
like always, any and all help is greatly appreciated.
P.S. if you would like to test it out, you can go to http://www.jakykong.net.tf/codebank/earchit.asp (http://jakykong.net.tf/codebank/searchit.asp). this is the page that is pure html and has the form that the user inputs the search terms.