Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 16
  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    query di ricerca per più campi select

    ciao a tutti,
    per questo form:

    <form method="get" action="../cerco/">
    <td><table width="206" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="143"><select name="modello" id="immobile" size="1" tabindex="6">
    <option value="" selected>TUTTE</option>
    <option value="appartamento">APPARTAMENTO</option>
    <option value="villetta">VILLETTA</option>
    </select></td>
    <td width="63"><input name="Go" value="Cerca" type="submit"></td>
    </tr>
    </table></td>
    </form>

    uso questa query:

    dim modello_cerca
    modello_cerca=trim(request.QueryString("modello"))

    if len(modello_cerca)=0 then
    strSQL="select * from Prodotti order by id asc"
    else
    strSQL = "SELECT * FROM Prodotti WHERE lcase(modello) like '"& lcase(replace(modello_cerca,"'","''")) &"%' ORDER BY id ASC"

    end if


    Ora dovrei aggiungere:

    <select name="citta" id="citta" onChange="dennis(this[this.selectedIndex].value)" size="1" tabindex="10">
    <option value="" selected>TUTTE</option>
    <option value="trecastagni">TRECASTAGNI</option>
    <option value="catania">CATANIA</option>

    </select>


    solo che il campo "citta" è contenuto nella tabella "Utenti"
    come si modifica la query aggiungendo: SELECT * FROM Utenti WHERE lcase(citta)
    ?

    grazie

  2. #2
    codice:
    dim modello_cerca, f
    modello_cerca=trim(request.QueryString("modello"))
    
    if len(modello_cerca)=0 then
    strSQL="select * from Prodotti"
    f=0
    else
    strSQL = "SELECT * FROM Prodotti WHERE lcase(modello) like '"& lcase(replace(modello_cerca,"'","''")) &"%'"
    f=1
    end if
    
    dim localita
    localita=trim(request.querystring("citta"))
    
    if len(localita)>0 then
        
    if f>0 then
    strSql=strSql & " where "
    else
    strSql=strSql & " and "
    end if
    
            strSql=strSql & " id in (select idutente from utente_prodotto where idutente in (select t2.id from Utenti t2 where lcase(citta)=lcase(""" & replace(localita,"'","''") & """))"
    
    end if
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  3. #3
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    grazie

    dovrei aggiungere un altro campo...... il campo "in" che sta nella tabella Prodotti..

    <select name="in" id="in" size="1" tabindex="10">
    <option value="" selected>TUTTE</option>
    <option value="affitto">AFFITTO</option>
    <option value="vendita">VENDITA</option>

    </select>


    in questa query:

    codice:
    dim modello_cerca, f
    modello_cerca=trim(request.QueryString("modello"))
    
    if len(modello_cerca)=0 then
    strSQL="select * from Prodotti"
    f=0
    else
    strSQL = "SELECT * FROM Prodotti WHERE lcase(modello) like '"& lcase(replace(modello_cerca,"'","''")) &"%'"
    f=1
    end if
    
    dim localita
    localita=trim(request.querystring("citta"))
    
    if len(localita)>0 then
        
    if f>0 then
    strSql=strSql & " and "
    else
    strSql=strSql & " where "
    end if
    
            strSql=strSql & " id in (select idprodotto from user_prodotti where iduser in (select t2.id from Utenti t2 where lcase(citta)=lcase('" & replace(localita,"'","''") & "')))"
    
    
    end if

  4. #4
    Utente di HTML.it L'avatar di wallrider
    Registrato dal
    Apr 2003
    Messaggi
    2,755
    non starai mica chiedendo la pappa pronta? VVoVe:
    RIP Cicciobenzina 9/11/2010

    "Riseminaciceli, i ceci nell'orto"

  5. #5
    Originariamente inviato da wallrider
    non starai mica chiedendo la pappa pronta? VVoVe:
    Ovvio.

  6. #6
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    grazie per le risp

    ho provato ad aggiungere una query:

    codice:
    dim modello_cerca, f
    modello_cerca=trim(request.QueryString("modello"))
    
    if len(modello_cerca)=0 then
    strSQL="select * from Prodotti"
    f=0
    else
    strSQL = "SELECT * FROM Prodotti WHERE lcase(modello) like '"& lcase(replace(modello_cerca,"'","''")) &"%'"
    f=1
    end if
    
    dim localita
    localita=trim(request.querystring("citta"))
    
    if len(localita)>0 then
        
    if f>0 then
    strSql=strSql & " and "
    else
    strSql=strSql & " where "
    end if
    
            strSql=strSql & " id in (select idprodotto from user_prodotti where iduser in (select t2.id from Utenti t2 where lcase(citta)=lcase('" & replace(localita,"'","''") & "')))"
    
    
    end if
    
    dim imm
    imm=trim(request.querystring("inav"))
    
    if len(imm)>0 then
        
    if f>0 then
    strSql=strSql & " and "
    else
    strSql=strSql & " where "
    end if
    
            strSql=strSql & "select * from Prodotti where lcase(inav) like '"& lcase(replace(imm,"'","''")) &"%'"
    
    
    end if

    mi da questo errore quando cerco con tutte e tre le select:

    [Microsoft][ODBC Microsoft Access Driver] Syntax error. in query expression 'lcase(modello) like 'appartamento%' and id in (select idprodotto from user_prodotti where iduser in (select t2.id from Utenti t2 where lcase(citta)=lcase('termoli'))) and select * from Prodotti where lcase(inav) like 'vendita%''.

    ci manca qualcosina... chi mi dice dove sbaglio?

    thx

    ps. non mi dite che devo studiare!!! ho visto dei video corsi..ma si capisce poco..melgio la pratica..es:

    http://www.sitowebflash.com/D7.avi

  7. #7
    Meglio la pratica? Certo. Basta saperla applicare.
    Sai concatenare pezzi di stringhe con variabili?
    Risolvimi questo:
    codice:
    nome = "Pippo"
    giorno = "domenica"
    ora = "dieci del mattino"
    Fammi un response.write di questo tipo:
    Buongiorno Pippo! Come stai? Sai che oggi è domenica? Ci vediamo alle dieci del mattino.

  8. #8
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    codice:
    Dim strRicerca
    
    if len(nome) > 0 then
    strRicerca = strRicerca & " AND Pippo = '" & nome & "'"
    end if
    
    if len(giorno) > 0 then
    strRicerca = strRicerca & " AND domenica = '" & giorno & "'"
    end if
    
    if len(ora) > 0 then
    strRicerca = strRicerca & " AND dieci del mattino = '" & ora & "'"
    end if

    sbagliato?

  9. #9
    Originariamente inviato da Lino80
    codice:
    Dim strRicerca
    
    if len(nome) > 0 then
    strRicerca = strRicerca & " AND Pippo = '" & nome & "'"
    end if
    
    if len(giorno) > 0 then
    strRicerca = strRicerca & " AND domenica = '" & giorno & "'"
    end if
    
    if len(ora) > 0 then
    strRicerca = strRicerca & " AND dieci del mattino = '" & ora & "'"
    end if

    sbagliato?

  10. #10
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    chi mi da una mano a capire come funziona?? thx

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 © 2026 vBulletin Solutions, Inc. All rights reserved.