Visualizzazione dei risultati da 1 a 8 su 8

Discussione: Select From Where

  1. #1

    Select From Where

    Buongiorno a TUTTI....

    Avrei bisogno di un aiutino sperando che qualcuno gentile possa aiutarmi...

    Faccio subito un esempio:

    rs.Open ("SELECT * FROM hardware WHERE nomeutente = 'PIPPO' ")
    Il codice qui sopra... fa una select dalla tabella HARDWARE pescando tutti i campi associati alla STRINGA "PIPPO"

    Ma se nello stesso form, precedentemente io avessi questa select...:


    <td>

    UTENTE:</p></td>
    <td><select name="Utente">
    <option value="PIPPO">PIPPO</option>
    <option value="PLUTO">PLUTO</option>
    <option selected></option>
    </select></td>


    oppure una textbox...:


    <tr>
    <td>UTENTE:</td>
    <td><input type="text" name="Utente" maxlength="25" style="width: 100%;"
    </tr>


    Come faccio a dire al codice che ho menzionato sopra, di fare una select dalla tabella HARDWARE pescando tutti i campi associati al contenuto selezionato nella COMBO o nella TEXTBOX compilata poco prima nel form ?

    Spero di essermi spiegato ....

    GRAZIE infinite a tutti!!!

  2. #2
    C'è nessuno ??

  3. #3
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Dovresti fare una query dinamica compilando la parte DOPO il WHERE in base a cosa l'utente ha selezionato o scritto nel campo di testo.
    Cerca nel forum, se ne è parlato.

    Roby

  4. #4
    Grazie per la risposta... ma ho cercato e quello che trovo è solo una marea di IF .... ELSE...

    Ma non penso che faccia al caso mio..

    Io non so' quale sarà il valore di PIPPO (che è una variabile) fino a quando l'utente non l'ha SELEZIONATA.


    Ho provato in tutti i modi... ma non ci sono riuscito.

    Può qualcuno postarmi un esempio ?

  5. #5
    non puoi farlo nella stessa pagina. devi fare una submit della form, e mandarla ad un'altra pagina. quest'altra pagina leggerà la select o la textbox della pagina chiamante, preparerà ed eseguirà la query. guarda le lezioni di base

  6. #6
    Beh.. dai.. ora è un po' piu chiaro...

    Grazie

  7. #7
    Sono di nuovo qui per chiedervi... se qualcuno è in grado di dirmi perchè non funziona questo:

    Qui potete provare il mio esempio e verificare che non funziona la seconda SELECT

    Mentre qui potete scaricare il database di prova se volete testarlo voi

    File "config.asp"
    codice:
    <%
    	Option Explicit
    '	On Error Resume Next
    	Response.Buffer = True
    	' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
    	Dim titolo
    	titolo = "Prova"
    	' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
    	Dim var_username, var_password
    	var_username = "admin"
    	var_password = "admin"
    	' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
    	Dim sc
    	sc = "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("\mdb-database\database.mdb")
    	' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
    %>
    File "richiesta_ass.asp"

    codice:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    
    
    
    
    <%
    	'If Session("admin") <> "OK" Then Response.Redirect "index.asp"
    	Dim cn, rs 
    	Set cn = Server.CreateObject("ADODB.Connection")
    	Set rs = Server.CreateObject("ADODB.Recordset")
    	
    	cn.Open sc
    	
    %>
    <html>
    <head>
    
    <LINK href="/utilities_marco/verdana.css" type="text/css" rel="stylesheet">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Assistenza Thera</title>
    <style type="text/css">
    <!--
    TABLE,LEGEND,INPUT 
    {
    font-family:"Trebuchet MS", Verdana, sans-serif; font-size:12px;
    }
    select {font-family:Verdana, Arial, sans-serif; font-size:10px;}
    
    -->
    </style>
    
    
    <link href="formattazione.css" type="text/css" rel="stylesheet">
    </head>
    <body>
    
    
    
    					<tr> 
    		<td width="40%">Utente</td>
    		<td width="60%">
    			<select onchange="location.href='richiesta_ass.asp?id=' + this.value" style="width: 100%;">
    				<option value="">Seleziona il tuo Nome Utente</option>
    				<%
    					rs.Open "SELECT * FROM utenti", cn, 1
    					While rs.EOF = False
    				%>
    				<option value="<%=rs("id")%>"><%Response.Write rs("nome") & " " & rs("cognome")%></option>
    				<%
    						rs.MoveNext
    					Wend
    					rs.Close
    				%>
    			</select>
    		</td>
    	</tr>
    
    	<tr height "30">
    	<td>&nbsp</td>
    	</tr>
    
    	<%
    		Dim id
    		id = Request.QueryString("id")
    		If Len(Trim(id)) > 0 Then
    			Dim utente
    			Set utente = cn.Execute("SELECT * FROM utenti WHERE id = " & id)
    	%>
    	<input type="hidden" name="id_cont" value="<%=utente("id")%>">
    	
    	<tr>
    		<td>Nome</td>
    		<td><input type="text" name="nome" maxlength="50" style="width: 100%;" value="<%=utente("nome")%>"></td>
    	</tr>
    	<tr>
    		<td>Cognome</td>
    		<td><input type="text" name="cognome" maxlength="50" style="width: 100%;" value="<%=utente("cognome")%>"></td>
    	</tr>
    	<tr>
    		<td>Nomeutente</td>
    		<td><input type="text" name="nomeutente" maxlength="50" style="width: 100%;" value="<%=utente("nomeutente")%>"></td>
    	</tr>
    	<%
    		Set utente = Nothing
    		End If
    	%>
    
    
    
    
    
    
    
    
    					
    
    
    
    					<tr> 
    		<td width="40%">Hardware</td>
    		<td width="60%">
    			<select onchange="location.href='richiesta_ass.asp?id=<%=id%>&' + this.value" style="width: 100%;">
    				<option value="">Seleziona l'hardware guasto</option>
    				<%
    					rs.Open "SELECT * FROM hardware", cn, 1
    					While rs.EOF = False
    				%>
    				<option value="<%=rs("id_hardware")%>"><%Response.Write rs("apparecchiatura") & " " & rs("modello")%></option>
    				<%
    						rs.MoveNext
    					Wend
    					rs.Close
    				%>
    			</select>
    		</td>
    	</tr>
    
    	<tr height "30">
    	<td>&nbsp</td>
    	</tr>
    
    	<%
    		Dim id_hard
    		
    		id_hard = Request.QueryString("id_hardware")
    		
    		If Len(Trim(id_hard)) <> 0 Then
    			Dim hardwarelist
    			Set hardwarelist = cn.Execute("SELECT * FROM hardware WHERE id_hardware = " & id_hard)
    	%>
    	<input type="hidden" name="id_hardware_cont" value="<%=hardwarelist("id_hardware")%>">
    	
    	<tr>
    		<td>Apparecchiatura</td>
    		<td><input type="text" name="apparecchiatura"  style="width: 100%;" value="<%=hardwarelist("apparecchiatura")%>"></td>
    	</tr>
    	<tr>
    		<td>Modello</td>
    		<td><input type="text" name="modello"  style="width: 100%;" value="<%=hardwarelist("modello")%>"></td>
    	</tr>
    	
    	<%
    		Set hardwarelist = Nothing
    		End If
    	%>
    
    
    
    
    </body>
    </html>
    
    <%
    	
    	Set rs = Nothing
    	cn.Close
    	Set cn = Nothing
    	
    	
    %>
    GRAZIE in anticipo a chiunque vorrà aiutarmi

  8. #8
    Riporto in Cima AIUTOOOOOOOOOOOOOOOOOOOOOO

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.