Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 18

Discussione: motore di ricerca

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    18

    motore di ricerca

    tipo=Request.form("r1")
    anno2=Request.form("anno")
    numeroda=Request.form("numeroda")
    numeroa=Request.form("numeroa")
    oggetto=Request.form("oggetto")
    datada=Request.form("giornodatada") + "/" + Request.form("mesedatada") + "/" + Request.form("annodatada")
    dataa=Request.form("giornodataa") + "/" + Request.form("mesedataa") + "/" + Request.form("annodataa")
    if dataa = "gg/mm/yyyy" then
    dataa = datada
    pubblicazioneda=Request.form("giornopubblicazioned a") + "/" + Request.form("mesepubblicazioneda") + "/" + Request.form("annopubblicazioneda")
    pubblicazionea=Request.form("giornopubblicazionea" ) + "/" + Request.form("mesepubblicazionea") + "/" + Request.form("annopubblicazionea")
    if pubblicazionea = "gg/mm/yyyy" then
    pubblicazionea = pubblicazioneda
    esecutivada=Request.form("giornoesecutivada") + "/" + Request.form("meseesecutivada") + "/" + Request.form("annoesecutivada")
    esecutivaa=Request.form("giornoesecutivaa") + "/" + Request.form("meseesecutivaa") + "/" + Request.form("annoesecutivaa")
    if esecutivaa = "gg/mm/yyyy" then
    esecutivaa = esecutivada

    oggetto=Request.form("oggetto")

    end if
    end if
    end if



    set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("mdb-database/laigueglia.mdb")
    sql ="SELECT id FROM documenti where tipo = '" & tipo & "' and anno = '" & anno & "'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, conn, 3, 3
    Do While Not rs.Eof

    a = rs.fields("id")




    if numeroda <> "" then
    sql2 ="SELECT id FROM documenti where numero between '" & numeroda & "' and '" & numeroa & "' and id = "' & a & "'"
    Set rs2 = Server.CreateObject("ADODB.Recordset")
    rs2.Open sql2, conn, 3, 3
    b = rs.fields("id")
    else
    sql2 ="SELECT id FROM documenti id = "' & a & "'"
    rs2.Open sql2, conn, 3, 3
    b = rs.fields("id")

    if oggetto <> "" then
    sql3 ="SELECT id FROM documenti where oggetto like '" & oggetto & "' and id = "' & b & "'"
    Set rs3 = Server.CreateObject("ADODB.Recordset")
    rs3.Open sql3, conn, 3, 3
    c = rs.fields("id")
    else
    sql3 ="SELECT id FROM documenti id = "' & b & "'"
    rs3.Open sql3, conn, 3, 3
    c = rs.fields("id")

    if datada <> "gg/mm/yyyy" then
    sql4 ="SELECT id FROM documenti where data between '" & datada & "' and '" & dataa & "' and id = "' & c & "'"
    Set rs4 = Server.CreateObject("ADODB.Recordset")
    rs4.Open sql4, conn, 3, 3
    d = rs.fields("id")
    else
    sql4 ="SELECT id FROM documenti id = "' & c & "'"
    rs4.Open sql4, conn, 3, 3
    d = rs.fields("id")

    if pubblicazioneda <> "gg/mm/yyyy" then
    sql5 ="SELECT id FROM documenti where datapubbl between '" & pubblicazioneda & "' and '" & pubblicazionea & "' and id = "' & c & "'"
    Set rs5 = Server.CreateObject("ADODB.Recordset")
    rs5.Open sql5, conn, 3, 3
    e = rs.fields("id")
    else
    sql5 ="SELECT id FROM documenti id = "' & d & "'"
    rs5.Open sql5, conn, 3, 3
    e = rs.fields("id")

    if esecutivada <> "gg/mm/yyyy" then
    sql6 ="SELECT id FROM documenti where dataesec between '" & esecutivada & "' and '" & esecutivaa & "' and id = "' & d & "'"
    Set rs6 = Server.CreateObject("ADODB.Recordset")
    rs6.Open sql6, conn, 3, 3
    f = rs.fields("id")
    else
    sql6 ="SELECT id FROM documenti id = "' & d & "'"
    rs6.Open sql6, conn, 3, 3
    f = rs.fields("id")



    response.write f
    rs.movenext
    loop


    end if
    end if
    end if
    end if
    end if
    end if



    Rs.Close
    Set RS = Nothing
    Rs1.Close
    Set RS1 = Nothing
    Rs2.Close
    Set RS2 = Nothing
    Rs3.Close
    Set RS3 = Nothing
    Rs4.Close
    Set RS4 = Nothing
    Rs5.Close
    Set RS5 = Nothing
    Rs6.Close
    Set RS6 = Nothing
    Conn.Close
    Set conn=Nothing

    %>


    scusate ragazzi in teoria questo script dovrebbe fungere da motore di ricerca, effettuando una ricerca su più condizioni, ora una volta eseguito mi restituisce questo errore

    Microsoft VBScript compilation error '800a040e'

    'loop' without 'do'

    /comunelaigueglia/ricercadelibere2.asp, line 879

    loop

    qualcuno sa darmi una mano ?

    grazie in anticipo

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Ricontrolla quel che hai scritto perché questo è errato:

    else
    sql6 ="SELECT id FROM documenti id = "' & d & "'"
    rs6.Open sql6, conn, 3, 3
    f = rs.fields("id")



    response.write f
    rs.movenext
    loop



    Come vedi all'interno di un else chiudi un loop ma non metti end if

    Roby

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    18
    la mia idea forse sbagliata è che per ogni record eseguisse tutte le sql per raffinare la ricerca in base hai valori inseriti nel form e poi con il loop ricominciasse del second record e cosi via

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Sul concetto ci siamo ma come vedi gli end if li hai messi a casaccio!

    Roby

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    18
    set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("mdb-database/laigueglia.mdb")
    sql ="SELECT id FROM documenti where tipo = '" & tipo & "' and anno = '" & anno & "'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, conn, 3, 3
    Do While Not rs.Eof

    a = rs.fields("id")




    if numeroda <> "" then
    sql2 ="SELECT id FROM documenti where numero between '" & numeroda & "' and '" & numeroa & "' and id = "' & a & "'"
    Set rs2 = Server.CreateObject("ADODB.Recordset")
    rs2.Open sql2, conn, 3, 3
    b = rs.fields("id")
    else
    sql2 ="SELECT id FROM documenti id = "' & a & "'"
    rs2.Open sql2, conn, 3, 3
    b = rs.fields("id")

    end if

    if oggetto <> "" then
    sql3 ="SELECT id FROM documenti where oggetto like '" & oggetto & "' and id = "' & b & "'"
    Set rs3 = Server.CreateObject("ADODB.Recordset")
    rs3.Open sql3, conn, 3, 3
    c = rs.fields("id")
    else
    sql3 ="SELECT id FROM documenti id = "' & b & "'"
    rs3.Open sql3, conn, 3, 3
    c = rs.fields("id")

    end if

    if datada <> "gg/mm/yyyy" then
    sql4 ="SELECT id FROM documenti where data between '" & datada & "' and '" & dataa & "' and id = "' & c & "'"
    Set rs4 = Server.CreateObject("ADODB.Recordset")
    rs4.Open sql4, conn, 3, 3
    d = rs.fields("id")
    else
    sql4 ="SELECT id FROM documenti id = "' & c & "'"
    rs4.Open sql4, conn, 3, 3
    d = rs.fields("id")

    end if

    if pubblicazioneda <> "gg/mm/yyyy" then
    sql5 ="SELECT id FROM documenti where datapubbl between '" & pubblicazioneda & "' and '" & pubblicazionea & "' and id = "' & c & "'"
    Set rs5 = Server.CreateObject("ADODB.Recordset")
    rs5.Open sql5, conn, 3, 3
    e = rs.fields("id")
    else
    sql5 ="SELECT id FROM documenti id = "' & d & "'"
    rs5.Open sql5, conn, 3, 3
    e = rs.fields("id")

    end if

    if esecutivada <> "gg/mm/yyyy" then
    sql6 ="SELECT id FROM documenti where dataesec between '" & esecutivada & "' and '" & esecutivaa & "' and id = "' & d & "'"
    Set rs6 = Server.CreateObject("ADODB.Recordset")
    rs6.Open sql6, conn, 3, 3
    f = rs.fields("id")
    else
    sql6 ="SELECT id FROM documenti id = "' & d & "'"
    rs6.Open sql6, conn, 3, 3
    f = rs.fields("id")

    end if

    response.write f
    rs.movenext
    loop





    Rs.Close
    Set RS = Nothing
    Rs1.Close
    Set RS1 = Nothing
    Rs2.Close
    Set RS2 = Nothing
    Rs3.Close
    Set RS3 = Nothing
    Rs4.Close
    Set RS4 = Nothing
    Rs5.Close
    Set RS5 = Nothing
    Rs6.Close
    Set RS6 = Nothing
    Conn.Close
    Set conn=Nothing

    %>
    ora credo che siano messi giusti ma mi restituisce questo errore


    Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

    /comunelaigueglia/ricercadelibere2.asp, line 817

  6. #6
    Il problema penso che sia nelle SELECT infatti il messaggio d'errore dice che non passi tutti i parametri

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    18
    ho ancora qualche problemino

    set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("mdb-database/laigueglia.mdb")
    sql ="SELECT id FROM documenti where tipo = '" & tipo & "' and anno = '" & anno2 & "'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, conn, 3, 3
    Do While Not rs.Eof

    a = rs.fields("id")




    if numeroda <> "" then
    sql2 ="SELECT id FROM documenti where numero between '" & numeroda & "' and '" & numeroa & "' and id = "' & a & "'"
    Set rs2 = Server.CreateObject("ADODB.Recordset")
    rs2.Open sql2, conn, 3, 3
    b = rs.fields("id")
    else
    sql2 ="SELECT id FROM documenti where id = "' & a & "'"
    response.write sql2
    Set rs2 = Server.CreateObject("ADODB.Recordset")
    rs2.Open sql2, conn, 3, 3
    b = rs.fields("id")


    perchè non passa il valore di " a " estrapolato tremite la prima sql nella seconda sql ?

  8. #8
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    18
    nessun genio nei paraggi ??

  9. #9
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Se il campo è contatore o numerico nella query elimina gli apici.

    Roby

  10. #10
    perchè non passa il valore di " a " estrapolato tremite la prima sql nella seconda sql ?
    Risolto questo problema (la soluzione di Roby72 potrebbe essere quella giusta, ciao Roby) incapperai almeno in questo altro:

    - nella variabile b non memorizzi il campo id del record estratto con la seconda query, ma rileggi un'altra volta quello estratto dalla prima (cioè a). Il secondo recordset è rs2, quindi devi scrivere
    codice:
    b = rs2.fields("id")
    e non
    codice:
    b = rs.fields("id")
    Inoltre lo script non ha molto senso, perchè con le query successive estrae nulla o al massimo lo stesso id che ha già estratto con la prima, e per farlo crea e gestisce una serie spaventosa di oggetti (recordset) con inutile complicazione del codice e dispendio di risorse del server.....

    A questo punto ti conviene costruire un'unica query in cui riunisci tutte le condizioni in base alle quali estrarre i records.......per esempio:

    codice:
    sql = "SELECT * FROM documenti WHERE tipo = '" & tipo & "' AND anno = '" & anno2 & "'"
    
    if numeroda <> "" then 
    sql = sql & " AND numero between '" & numeroda & "' and '" & numeroa & "'"
    end if
    
    if oggetto <> "" then 
    sql = sql & " AND oggetto like '" & oggetto & "'"
    end if
    
    .............
    le altre condizioni
    .............
    
    Set rs = Server.CreateObject("ADODB.Recordset") 
    rs.Open sql, conn, 3, 3 
    Do until rs.Eof
    
    ...............
    presentazione a video dei records eventualmente estratti
    ................
    
    rs.movenext
    loop
    Come vedi la query viene costruita in modo dinamico a seconda delle condizioni, e alla fine eseguita una sola volta....meglio, no?

    E' nato www.lombardiamotori.it

    www.universocase.it: il primo portale italiano di annunci immobiliari gratuiti e autogestiti!

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.