Ciao,
ho un problema su un piccolo motore di ricerca che ho creato.
Praticamente ho una sola tabella nel database (Access) che contiene tutti i dati di cui ho bisogno.
Il motore è formato da due campi dove il primo pesca in alcune colonne della tabella mentre il secondo pesca in altri così:
campo 1
> titolo
> descrizione
> ...
campo 2
> provincia
> regione
> ...
il problema è che quando inserisco dei valori nel campo 1 e poi nel campo 2 ovviamente mi deve filtrare i risultati.
Ho scritto questo codice ma non va come vorrei:
SQL = SQL & "WHERE ("
if left(lcase(KeywordArray(j)),5) = "link:" then
if Instr(1,lcase(KeywordArray(j)),"http://") then
SQL = SQL & "Tabella.URL LIKE '%" & right(lcase(KeywordArray(j)),len(KeywordArray(j)) - 5) & "%'"
else
SQL = SQL & "Tabella.URL LIKE '%http://" & right(lcase(KeywordArray(j)),len(KeywordArray(j)) - 5) & "%'"
end if
else
if len(tempkeyword) > 0 then
for j = lbound(KeywordArray) to ubound(KeywordArray)
if request.form("type") = "EX" then
SQL = SQL & "Tabella.Titolo = '" & CheckString(KeywordArray(j)) & "'"
else
SQL = SQL & "Tabella.Titolo LIKE '%" & CheckString(KeywordArray(j)) & "%'"
end if
if j <> ubound(KeywordArray) then
SQL = SQL & " AND "
end if
next
else
SQL = SQL & "Tabella.Titolo LIKE '%%'"
end if
SQL = SQL & " AND "
if len(Tempkeyword) > 0 then
for j = lbound(KeywordArray) to ubound(KeywordArray)
if request.form("type") = "EX" then
SQL = SQL & "Tabella.Descrizione = '" & CheckString(KeywordArray(j)) & "'"
else
SQL = SQL & "Tabella.Descrizione LIKE '%" & CheckString(KeywordArray(j)) & "%'"
end if
if j <> ubound(KeywordArray) then
SQL = SQL & " AND "
end if
next
else
SQL = SQL & "Tabella.Descrizione LIKE '%%'"
end if
SQL = SQL & " AND "
if len(Tempkeyword) > 0 then
for j = lbound(KeywordArray) to ubound(KeywordArray)
if request.form("type") = "EX" then
SQL = SQL & "Tabella.Servizi = '" & CheckString(KeywordArray(j)) & "'"
else
SQL = SQL & "Tabella.Servizi LIKE '%" & CheckString(KeywordArray(j)) & "%'"
end if
if j <> ubound(KeywordArray) then
SQL = SQL & " AND "
end if
next
else
SQL = SQL & "Tabella.Servizi LIKE '%%'"
end if
SQL = SQL & " AND "
if len(Tempkeyword) > 0 then
for j = lbound(KeywordArray) to ubound(KeywordArray)
if request.form("type") = "EX" then
SQL = SQL & "Tabella.Titolo = '" & CheckString(KeywordArray(j)) & "'"
else
SQL = SQL & "Tabella.Titolo LIKE '%" & CheckString(KeywordArray(j)) & "%'"
end if
if j <> ubound(KeywordArray) then
SQL = SQL & " AND "
end if
next
else
SQL = SQL & "Tabella.Titolo LIKE '%%'"
end if
SQL = SQL & " OR "
if len(Tempkeyword02) > 0 then
for j = lbound(KeywordArray02) to ubound(KeywordArray02)
if request.form("type") = "EX" then
SQL = SQL & "Tabella.Provincia = '" & CheckString(KeywordArray02(j)) & "'"
else
SQL = SQL & "Tabella.Provincia LIKE '%" & CheckString(KeywordArray02(j)) & "%'"
end if
if j <> ubound(KeywordArray02) then
SQL = SQL & " OR "
end if
next
else
SQL = SQL & "Tabella.Provincia LIKE '%%'"
end if
SQL = SQL & " OR "
if len(Tempkeyword02) > 0 then
for j = lbound(KeywordArray02) to ubound(KeywordArray02)
if request.form("type") = "EX" then
SQL = SQL & "Tabella.Prov = '" & CheckString(KeywordArray02(j)) & "'"
else
SQL = SQL & "Tabella.Prov LIKE '%" & CheckString(KeywordArray02(j)) & "%'"
end if
if j <> ubound(KeywordArray02) then
SQL = SQL & " OR "
end if
next
else
SQL = SQL & "Tabella.Prov LIKE '%%'"
end if
SQL = SQL & " OR "
if len(Tempkeyword02) > 0 then
for j = lbound(KeywordArray02) to ubound(KeywordArray02)
if request.form("type") = "EX" then
SQL = SQL & "Tabella.Regione = '" & CheckString(KeywordArray02(j)) & "'"
else
SQL = SQL & "Tabella.Regione LIKE '%" & CheckString(KeywordArray02(j)) & "%'"
end if
if j <> ubound(KeywordArray02) then
SQL = SQL & " OR "
end if
next
else
SQL = SQL & "Tabella.Regione LIKE '%%'"
end if
end if
SQL = SQL & ")"
Non riesco a capire come mettere le condizioni AND e OR.
Qualcuno mi può aiutare ?
Grazie.