01. maj 2003 - 12:04Der er
9 kommentarer og 1 løsning
Et or for meget...
Hej, jeg har en søgefunktion som benytter checkbokse til at opstillekriterier med, som den henter data fra en access database med. Problemet er, at hvis man markerer mere end 2 checkbokse, så kommer der et or for meget - markerer man 3, kommer der to or, marker man fire kommer der tre o.s.v.
Her er et uddrag fra scriptet: if request("str1") <> "" then strSQL = strSQL & "str='" & request("str1") & "' " end if if request("str1") <> "" and request("str2") <> "" then strSQL = strSQL & "or " end if if request("str1") <> "" and request("str3") <> "" then strSQL = strSQL & "or " end if if request("str1") <> "" and request("str4") <> "" then strSQL = strSQL & "or " end if if request("str1") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str2") <> "" then strSQL = strSQL & "str='" & request("str2") & "' " end if if request("str2") <> "" and request("str3") <> "" then strSQL = strSQL & "or " end if if request("str2") <> "" and request("str4") <> "" then strSQL = strSQL & "or " end if if request("str2") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str3") <> "" then strSQL = strSQL & "str='" & request("str3") & "' " end if if request("str3") <> "" and request("str4") <> "" then strSQL = strSQL & "or " end if if request("str3") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str4") <> "" then strSQL = strSQL & "str='" & request("str4") & "' " end if if request("str4") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str5") <> "" then strSQL = strSQL & "str='" & request("str5") & "' " end if
Jeg har sat en response.write strsql response.end ind før sætningen eksekveres, og her er meddelelsen, hvis man har markeret de fire første (str1,2,3 og 4):
Select * from Cichlider where (str='str1' or or or str='str2' or or str='str3' or str='str4' )
for i = 1 to 4 if s(i) <> "" then if strSQL <> "" then strSQL = strSQL & "or " & s(i) else strSQL = s(i) & " " end if end if next
Nemmere, ikke?
hth jes
Synes godt om
Slettet bruger
01. maj 2003 - 12:25#2
Kunne du ikke lave noget med strSQL= "" if chkbox1 then strSQL = strSQL & " felt = vaerdi OR " end if if chkbox2 then strSQL = strSQL & " felt = vaerdi OR " end if . . . if chkbox99 then (eller hvor mange du nu har) strSQL = strSQL & " felt = vaerdi OR " end if
strSQL = "SELECT * from cichilider where " & mid(strSQL, 1, len(strSQL) - 3) 'Fjerner den sidste OR
Jes>>> Jeg kan ikke hitte ud af at sætte det ind i scriptet... Er det for meget forlangt, hvis jeg beder dig om at skrive det ind i det uddrag jeg har vist...
if request("str1") <> "" then strSQL = strSQL & "str='" & request("str1") & "' " end if if request("str1") <> "" and request("str2") <> "" then strSQL = strSQL & "or " end if if request("str1") <> "" and request("str3") <> "" then strSQL = strSQL & "or " end if if request("str1") <> "" and request("str4") <> "" then strSQL = strSQL & "or " end if if request("str1") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str2") <> "" then strSQL = strSQL & "str='" & request("str2") & "' " end if if request("str2") <> "" and request("str3") <> "" then strSQL = strSQL & "or " end if if request("str2") <> "" and request("str4") <> "" then strSQL = strSQL & "or " end if if request("str2") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str3") <> "" then strSQL = strSQL & "str='" & request("str3") & "' " end if if request("str3") <> "" and request("str4") <> "" then strSQL = strSQL & "or " end if if request("str3") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str4") <> "" then strSQL = strSQL & "str='" & request("str4") & "' " end if if request("str4") <> "" and request("str5") <> "" then strSQL = strSQL & "or " end if if request("str5") <> "" then strSQL = strSQL & "str='" & request("str5") & "' " end if
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.