search i database fra to tabeller.
//Scriptet ser slik ut:Hvordan får jeg det til å søke i to tabeller og flere kolonner enn en?
Jeg har laget en sql men den virker ikke:
"SELECT DocID, DocMenuTitle,DocLink,DocLinkUrl,DocLinkTarget,DocTitle,DocContent,DocCreated,NewsID,NewsTittel,Regdato FROM tblWPDocuments, tblWPNews Where DocMenuTitle LIKE '%" & strKeyword(0) & "%' AND DocTitle LIKE '%" & (0) & "%' AND DocContent LIKE '%" & strKeyword(0) & "%' AND NewsTittel LIKE '%" & strKeyword(0) & "%' AND Ingress LIKE '%" & strKeyword(0) & "%' AND Brodtekst LIKE '%" & strKeyword(0) & "%' ORDER BY DocCreated,RegDato DESC"
<%
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdText = &H0001
Const adUseClient = 3
Dim currentPage
If Len(Request.QueryString("currentPage")) = 0 Then
currentPage = 1
Else
currentPage = CInt(Request.QueryString("currentPage"))
End If
Dim recordsToShow
recordsToShow = 10
Dim strKeyword
strKeyword = split(Trim(Request.QueryString("q")), " ")
Set adoRs = CreateObject("ADODB.Recordset")
adoRs.CursorLocation = adUseClient
adoRs.PageSize = recordsToShow
adoRs.CacheSize = recordsToShow
strSQL = "SELECT DocID, DocMenuTitle,DocLink,DocLinkUrl,DocLinkTarget,DocTitle,DocContent,DocCreated,NewsID,NewsTittel,Regdato FROM tblWPDocuments, tblWPNews Where DocMenuTitle LIKE '%" & strKeyword(0) & "%' AND DocTitle LIKE '%" & (0) & "%' AND DocContent LIKE '%" & strKeyword(0) & "%' AND NewsTittel LIKE '%" & strKeyword(0) & "%' AND Ingress LIKE '%" & strKeyword(0) & "%' AND Brodtekst LIKE '%" & strKeyword(0) & "%' ORDER BY DocCreated,RegDato DESC"
Response.Write(strSQL)
'Response.End
Select Case UBound(strKeyword)
Case 0 adoRs.Open "select * from tblWPDocuments where DocContent like '%" & strKeyword(0) & "%' order by DocCreated desc", adoCn, adOpenForwardOnly, adLockReadOnly, adCmdText
Case 1 adoRs.Open "select * from tblWPDocuments where DocContent like '%" & strKeyword(0) & "%' and DocContent like '%" & strKeyword(1) & "%' order by DocCreated desc", adoCn
Case 2 adoRs.Open "select * from tblWPDocuments where DocContent like '%" & strKeyword(0) & "%' and DocContent like '%" & strKeyword(1) & "%' and DocContent like '%" & strKeyword(2) & "%' order by DocCreated desc", adoCn
Case Else adoRs.Open "select * from tblWPDocuments where DocContent like '%" & strKeyword(0) & "%' and DocContent like '%" & strKeyword(1) & "%' and DocContent like '%" & strKeyword(2) & "%' order by DocCreated desc", adoCn
End Select
If Not adoRs.EOF Then
Dim totalpages
totalpages = adoRs.PageCount
adoRs.AbsolutePage = currentPage
%>
<table width="601" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="601" height="<%=strHeight%>"></td>
</tr>
<tr>
<td class="heading" width="601" height="15"><font color="#<%=strTMouseover%>">Søk i nettstedet</font></td>
</tr>
</table>
<%
Response.Write "Side " & currentPage & " av " & totalPages & "<br>"
Response.Write "Antall treff funnet : " & adoRs.RecordCount & "<br>"
Response.Write "Søke resultater for : " & Request.QueryString("q")
Response.Write "<br><br>"
Dim rcount, x
For i = 1 To adoRs.PageSize
rcount = i
If currentPage > 1 Then
For x = 1 To (currentPage - 1)
rcount = 10 + rcount
Next
End If
If Not adoRs.EOF Then
strDato = adoRs("DocCreated")
strDay = Day( strdato )
if len(strDay) = 1 then
strDay = "0" & strDay
end if
strMonth = Month( strdato )
if len(strMonth) = 1 then
strMonth = "0" & strMonth
end if
strYear = Year( strdato )
if len(strYear) = 1 then
strYear = "0" & strYear
end if
strCreated = strDay & "." & strMonth & "." & strYear
Response.Write rcount & ") <b><a href=""url.asp?url=wp.asp?DocID=" & adoRs("DocId") & """>" & adoRs("DocTitle") & "</a></b><br>" & vbcrlf
Response.Write "URL : " & strCodeBaseUrl & "url.asp?url=wp.asp?DocID=" & adoRs("DocID") & "</b><br>" & vbcrlf
Response.Write "Dato opprettet : " & strCreated & "<br><br>" & vbcrlf
adoRs.MoveNext
End If
Next
If currentPage > 1 Then
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?currentPage=" & currentPage - 1 & "&q=" & Server.URLEncode(Request.QueryString("q")) & """>Tilbake</a>"
Else
Response.Write "<u style=""color : silver;"">Tilbake</u>"
End If
Response.Write " "
If CInt(currentPage) <> CInt(totalPages) Then
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?currentPage=" & currentPage + 1 & "&q=" & Server.URLEncode(Request.QueryString("q")) & """>Neste</a>"
Else
Response.Write "<u style=""color : silver;"">Neste</u>"
End If
Else
Response.Write "<b> Beklager, ingen treff.</b>" & vbcrlf
End If
Set adoRs = Nothing
%>
