Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2003
    Messaggi
    56

    Problema con due campi di ricerca

    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.

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2003
    Messaggi
    56
    Nessuno ha qualche suggerimento ?

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2003
    Messaggi
    56
    Un aiutino raga ??

    Stò impazzendo e devo cercare di risolverlo

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Stampa la query a video così capisci il motivo.

    Roby

  5. #5
    Utente di HTML.it
    Registrato dal
    Mar 2003
    Messaggi
    56
    Questo è il risultato della query:

    ***SELECT DISTINCT * FROM Tabella WHERE (Tabella.Titolo LIKE '%g%' AND Tabella.Descrizione LIKE '%g%' AND Tabella.Servizi LIKE '%g%' AND Tabella.Titolo LIKE '%g%' OR Tabella.Provincia LIKE '%va%' OR Tabella.Prov LIKE '%va%' OR Tabella.Regione LIKE '%va%') AND (Tabella.PublishOnWeb = True)***

    Quello che mi serve ottenere è cge la query verifichi che il valore immesso nel primo campo sia verificato in Titolo, Descrizione e Servizi mentre il secondo valore sia verificato in Provincia, Prov e Regione.

  6. #6
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    ***SELECT DISTINCT * FROM Tabella WHERE (Tabella.Titolo LIKE '%g%' AND Tabella.Descrizione LIKE '%g%' AND Tabella.Servizi LIKE '%g%' AND Tabella.Titolo LIKE '%g%') AND (Tabella.Provincia LIKE '%va%' AND Tabella.Prov LIKE '%va%' AND Tabella.Regione LIKE '%va%') AND (Tabella.PublishOnWeb = True)***
    Utilizza le parentesi e la giusta combinazione AND / OR

    Roby

  7. #7
    Utente di HTML.it
    Registrato dal
    Mar 2003
    Messaggi
    56
    Sono riuscito ha risolvere.

    Grazie mille per l'aiuto

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.