Avatar billede hifi4all Nybegynder
26. september 2005 - 18:38 Der er 1 løsning

SQL sætning - inkludere flere tabeller i søgning

Hej!

Jeg har en søge funktion med SQL sætning som nedenstående.
Ønsket er at få "zoneid" med fra tabellen iArticlesZones i søgningen, så de kan skrives ud til brugeren.

Umiddelbart kan jeg ikke hitte på en fornuftig løsning, men få det til at virke med "kode1", men resultatet er en MEGET langsom søgning og udskrivning af resultatt

Kode1 (som ikke er ønskelig):
<%
Dim keyword, zone
keyword = " '%' "
zone = " % "

    if Request.Form("keyword") <> "" then
        keyword =  " '%" & Request.Form("keyword")& "%' "
    end if

    if Request.Form("zone") <> "" then
        zone =  " '" & Request.Form("zone")& "' "
    end if

    if Request.QueryString("keyword") <> "" then
        keyword =  " '%" & Request.QueryString("keyword")& "%' "
    end if
    if Request.QueryString("zone") <> "" then
        zone =  " '" & Request.QueryString("zone")& "' "
    end if

set rsAds = Server.CreateObject("ADODB.Recordset")
rsAds.ActiveConnection = MM_Conn_String
if zoneid<>"" then
rsAds.Source = "SELECT * FROM articles, iArticlesZones WHERE articles.articleid = iArticlesZones.articleid AND articles.status = 1 AND (headline LIKE " & keyword & " OR article LIKE " & keyword & " OR summary LIKE " & keyword & " OR source LIKE " & keyword & ") AND articles.articleid in (select articleid from iArticlesZones where zoneid="&zone&") ORDER BY articles.articleid DESC"
else
rsAds.Source = "SELECT * FROM articles, iArticlesZones WHERE articles.articleid = iArticlesZones.articleid  AND articles.status = 1 AND (headline LIKE " & keyword & " OR article LIKE " & keyword & " OR summary LIKE " & keyword & " OR source LIKE " & keyword & ") ORDER BY articles.articleid DESC"
end if
rsAds.CursorType = 0
rsAds.CursorLocation = 2
rsAds.LockType = 3
rsAds.Open()
rsAds_numRows = 0

Kode 2 (som er lyn hurtig):
if zoneid<>"" then
rsAds.Source = "SELECT * FROM articles WHERE articles.status = 1 AND (headline LIKE " & keyword & " OR article LIKE " & keyword & " OR summary LIKE " & keyword & " OR source LIKE " & keyword & ") AND articles.articleid in (select articleid from iArticlesZones where zoneid="&zone&") ORDER BY articles.articleid DESC"
else
rsAds.Source = "SELECT * FROM articles WHERE articles.status = 1 AND (headline LIKE " & keyword & " OR article LIKE " & keyword & " OR summary LIKE " & keyword & " OR source LIKE " & keyword & ") ORDER BY articles.articleid DESC"
end if

Nogen der kan hjælpe?

På forhånd tak!
Avatar billede hifi4all Nybegynder
04. oktober 2005 - 09:22 #1
lukker
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