Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: search form


Message #1 by "Mattias Nerde" <mda99mjo@s...> on Wed, 23 May 2001 11:29:14
Hi I have created a searchform in ASP and VBScript. I want to search my 

database with a freetext search. This works, but only for one of the words 

im typing in the form. If I type in (+f2 +f3) it only searches for the 

last word (f3). Im not very good on programming but Im learning. Please 

help me to understand what Im doing wrong.

Here is some of the code.



Dim strURL     



Dim cnnSearch  

Dim rstSearch  

Dim strDBPath  



Dim strSQL     

Dim strSearch  



Dim iPageCurrent 

Dim iPageCount   

Dim iRecordCount 

Dim I            





strURL = Request.ServerVariables("URL")





strSearch = Request.QueryString("search")





If Request.QueryString("page") = "" Then

	iPageCurrent = 1

Else

	iPageCurrent = CInt(Request.QueryString("page"))

End If





%>

<p>Sök i <b>FAQ</b>  (% returnerar alla)</p>

<form action="<%= strURL %>" method="get">

<input name="search" value="<%= strSearch %>" />

<input type="submit" />

</form>



<%

If strSearch <> "" Then

	

Dim test

Dim index, currentpos, arraypos

Dim tempStr

Dim array(5)

	

currentpos = 1

arraypos = 0

	

if mid(strSearch,1,1) = "+" then

  for index = 2 to Len(strSearch)

  if (mid(strSearch, index+1, 1) = "+") or (mid(strSearch, index+1, 1) = "-

  ") or (index = Len(strSearch)) then

  tempStr = trim(Mid(strSearch, currentpos, index-currentpos +1))

  Response.write("<BR>" & mid(tempStr,2,len(tempStr)) )

  array(arraypos) = mid(tempStr,2,len(tempStr))

  currentpos = index

  end if	

next

  else 

     array(0) = strSearch

  end if

	

	strDBPath = Server.MapPath("database.mdb")



	Set cnnSearch = Server.CreateObject("ADODB.Connection")



	cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data              

        Source=C:\Inetpub\wwwroot\Intranet_produkt\FAQ\ABB.mdb"



strSQL = "SELECT *" _

& "FROM FrågaSvar " _

& "WHERE Namn LIKE '%" & Replace(array(0), "'", "''") & "%' " _

& "OR Fråga LIKE '%" & Replace(array(0), "'", "''") & "%' " _

& "OR Svar LIKE '%" & Replace(array(0), "'", "''") & "%' " _

& "OR Relaterad_Info LIKE '%" & Replace(array(0), "'", "''") & "%' " _

& "OR Datum LIKE '%" & Replace(array(0), "'", "''") & "%' " _

& "OR Sign LIKE '%" & Replace(array(0), "'", "''") & "%' " _

& "OR Kund LIKE '%" & Replace(array(0), "'", "''") & "%' " _

& "ORDER BY Namn;"



Set rstSearch = Server.CreateObject("ADODB.Recordset")

rstSearch.PageSize  = PAGE_SIZE

rstSearch.CacheSize = PAGE_SIZE



rstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdText



I hope you understand what I mean.

Best regards

Mattias

  Return to Index