Avatar billede kag Nybegynder
28. januar 2004 - 12:30 Der er 1 kommentar

Æ,ø og Å i en søgning

Jeg har en asp side, som sender en forespørgsel til en database, og dernæst sender indholdet til en resultatside.

Alt virker, bare ikke når søgningen indeholder æ,ø og Å

Koden er nedenfor...





<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/Conn_notatsamling.asp" -->
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.QueryString("Soegefelt") <> "") Then
  Recordset1__MMColParam = Request.QueryString("Soegefelt")
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_Conn_notatsamling_STRING
Recordset1.Source = "SELECT *  FROM NotatSamling, Kategorier  WHERE Link Like '%" + Replace(Recordset1__MMColParam, "'", "''") + "%' AND Notatsamling.Kategori=Kategorier.KategoriID"


Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
Dim MM_paramName
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
  MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
  End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
  End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
  MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "")  Then
  MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
  MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> "") Then
    MM_joinChar = "&"
  Else
    MM_joinChar = ""
  End If
End Function
%>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<p>
  <%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
  <a href="<%= (Recordset1.Fields.Item("Kategorinavn").Value)%>/<%=(Recordset1.Fields.Item("Link").Value)%>"><%=(Recordset1.Fields.Item("Overskrift").Value)%></a>
  <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
</p>
<p>&nbsp; </p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
Avatar billede soda Nybegynder
28. januar 2004 - 14:35 #1
Du kunne tage din SQL query og konverter alle danske bogstaver til gammeldansk på følgende måde..

Function ConvertToEng(sStr)
    sStr = Replace(sStr,"Æ","AE")
    sStr = Replace(sStr,"æ","ae")
    sStr = Replace(sStr,"Ø","OE")
    sStr = Replace(sStr,"ø","oe")
    sStr = Replace(sStr,"Å","AA")
    sStr = Replace(sStr,"å","aa")
    ConvertToEng = sStr
End Function

Det kræver så bare, at du også køre stringen igennem når du skriver den ud på siden, så du får de danske bogstaver tilbage igen. Dertil skal så laves en funtion der gør det modsatte af overstående.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester