Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 19
  1. #1

    Query group by e listbox

    Con questo code estraggo da una listbox dinamica tutti i valori associati a quel determinato ID_ABC:
    codice:
    ..........
    if ID_ABC > 0 then 
    
    sql = "select nome from tbl where ID_ABC = " & ID_ABC & " group by nome"
    
    set rs = conn.execute(sql) 
    do while not rs.eof
    %> 
    <h1 align="left"><%=rs("nome")%></h1> 
    <%
    rs.movenext
    loop
    rs.close 
    set rs = nothing 
    end if
    conn.close 
    set conn = nothing 
    %>
    Vorrei sapere:

    - come posso fare in modo che l'elenco dei nomi restituiti diventi linkabile e mi porti al record corrispondente nel dbase;

    - come faccio nella query eventualmente a selezionare più campi e raggrupparli sempre per nome.

    Grazie.

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    ..........
    if ID_ABC > 0 then 
    
    sql = "select nome from tbl where ID_ABC = " & ID_ABC & " group by nome"
    
    set rs = conn.execute(sql) 
    do while not rs.eof
    %> 
    <h1 align="left"><%=rs("nome")%></h1> 
    <%
    rs.movenext
    loop
    rs.close 
    set rs = nothing 
    end if
    conn.close 
    set conn = nothing 
    %>
    Per aggiungere nuovi campi li devi mettere nella select ed aggiungerli nel group by dopo il campo "nome".
    Sicuro ti serva il group by?

    Roby

  3. #3
    Grazie Roby; in effetti il group by adesso non serve più perchè richiamo il dettaglio del record con il code che mi hai suggerito:
    codice:
    <h1 align="left"><%=rs("nome")%></h1>
    la mia pagina che corrisponde a quella che tu hai chiamato dettaglio però non estrae nulla, perchè? :master:

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Dipende quello che ci hai messo in "dettaglio.asp"...


    Roby

  5. #5
    Originariamente inviato da Roby_72
    Dipende quello che ci hai messo in "dettaglio.asp"...


    Roby
    dettaglio.asp:
    codice:
    <%
    Session.LCID = 1040
    
    tabella1 = Request.form("tabella1")
    
    Dim strDenominazione 
    strDenominazione = Replace(Request("tabella1"), "_", " ") 
    
    Dim ConnDown
    Set ConnDown=Server.CreateObject("ADODB.Connection")
    ConnDown.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& server.MapPath(path&"upload.mdb")
    Dim SQLDown,RECDown
    
    if tabella1 = "TUTTI" then
    
    SQLDown = "select * from tbl"
    Set RECDown = ConnDown.Execute(SQLDown)
    
    else
    
    SQLDown="SELECT * FROM tbl WHERE nome = '"&strDenominazione&"' order by ID asc" 
    Set RECDown=ConnDown.Execute(SQLDown)
    
    end if
    %>
    
    <td align="center"><%=RECDown("nome")%></td>
     
    <%
    RECDown.MoveNext
    WEnd
    end if
    RECDown.Close
    ConnDown.Close
    Set RECDown = Nothing
    Set ConnDown = Nothing
    %>

  6. #6
    Modifico così, ma non dà errore e non estrae nulla:
    codice:
    Session.LCID = 1040
    
    ID_ABC = request.querystring("ID_ABC") 
    
    Dim ConnDown
    Set ConnDown=Server.CreateObject("ADODB.Connection")
    ConnDown.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& server.MapPath(path&"upload.mdb")
    Dim SQLDown,RECDown
    
    if tabella1 = "TUTTI" then
    
    SQLDown = "select * from tbl"
    Set RECDown = ConnDown.Execute(SQLDown)
    
    else
    
    SQLDown="SELECT * FROM tbl WHERE nome = '"&ID_ABC&"' order by ID asc" 
    Set RECDown=ConnDown.Execute(SQLDown) 
    end if
    %>
    
    <td align="center"><%=RECDown("nome")%></td>
     
    <%
    RECDown.MoveNext
    WEnd
    end if
    RECDown.Close
    ConnDown.Close
    Set RECDown = Nothing
    Set ConnDown = Nothing
    %>

  7. #7
    Il dbase è strutturato così:

    tabella1 = ID_ABC; Squadra
    tabella2 = ID; ID_ABC; Nome

    Relazione uno-a-molti tra ID_ABC di tabella1 e ID_ABC di tabella2.

    Quello che vorrei fare è selezionando la squadra mi dà l'elenco dei nomi (questo funziona) e poi cliccando sul nome mi faccia vedere il record corrispondente a quel nome... :master:

  8. #8
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    Session.LCID = 1040
    
    ID_ABC = request.querystring("ID_ABC") 
    
    Dim ConnDown
    Set ConnDown=Server.CreateObject("ADODB.Connection")
    ConnDown.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& server.MapPath(path&"upload.mdb")
    Dim SQLDown,RECDown
    
    if ID_ABC = "" then
    SQLDown = "select * from tbl"
    else
    SQLDown="SELECT * FROM tbl WHERE nome = "&ID_ABC&" order by ID" 
    end if
    
    Set RECDown=ConnDown.Execute(SQLDown) 
    if not RECDown.EOF then
    do while not RECDown.EOF
    
    response.write RECDown("nome")%>
    
    <%
    RECDown.MoveNext
    Loop
    end if
    RECDown.Close
    ConnDown.Close
    Set RECDown = Nothing
    Set ConnDown = Nothing
    %>
    Roby

  9. #9
    So che non ci crederai, ma così mi estrae tutti i records del dbase...

  10. #10
    Questo è il code della listbox:
    codice:
    <% 
    pagina = request.servervariables("path_info") 
    ID_ABC = request.querystring("ID_ABC") 
    
    if len(ID_ABC) > 0 and isnumeric(ID_ABC) then 
    id = clng(ID_ABC) 
    else 
    id = 0 
    end if 
    
    set conn = server.createobject("adodb.connection") 
    conn.open "DRIVER={Microsoft Access Driver (*.mdb)};" &_ 
    "DBQ="& Server.MapPath("upload.mdb") 
    
    sql = "select * from tabella1 order by nome_squadra" 
    
    set rs = conn.execute(sql) 
    
    if not rs.eof then 
    %>
    
    <option value="<%=pagina%>?id_ABC=0">Selezionare Nome squadra</option> 
    
    <% do until rs.eof %> 
    
    <option value="<%=pagina%>?id_ABC<%=rs("ID_ABC)%>"<% if rs("ID_ABC") = id_ABC then %> selected<% end if %>><%=rs("nome_squadra")%></option> 
    
    <% 
    rs.movenext 
    loop 
    end if 
    %> 
    </select></font><p style="margin-top: 0; margin-bottom: 0" align="left"> 
    <font size="2" face="Verdana"> 
    <% 
    rs.close 
    set rs = nothing 
    
    if ID_ABC > 0 then 
    
    sql = "select nome from tabella2 where ID_ABC = " & ID_ABC & " group by nome"
    
    set rs = conn.execute(sql) 
    
    do while not rs.eof
    
    %>
    
    <%=rs("nome")%> 
    
    <%
    rs.movenext
    loop
    
    rs.close 
    set rs = nothing 
    
    end if
    conn.close 
    set conn = nothing 
    %>
    ed un volta selezionato il nome della squadra mi restituisce tutti i giocatori di quella determinata squadra... non riesco ad avere il dettaglio di ciascun giocatore...

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.