Devo fare una select che prenda i dati da una tabella presente in un data-base da dove comincio?
Esiste uno script asp js o php pronto che voi sappiate?
<select size="1" name="D1">
Grazie in anticipo.
Devo fare una select che prenda i dati da una tabella presente in un data-base da dove comincio?
Esiste uno script asp js o php pronto che voi sappiate?
<select size="1" name="D1">
Grazie in anticipo.
Originariamente inviato da ALESSANDRO007
Devo fare una select che prenda i dati da una tabella presente in un data-base da dove comincio?
Esiste uno script asp js o php pronto che voi sappiate?
<select size="1" name="D1">
Grazie in anticipo.![]()
In ASP si fa così ( php e js non sono materia di questo forum... )
codice:<SELECT size="1" NAME="Gestione"> <option>Seleziona gestione di riferimento</option> <% strSql = " SELECT * FROM TABELLA ORDER BY ID ASC " Set Rs = Server.CreateObject("ADODB.Recordset") Rs.Open strSql, objCONN If Not Rs.EOF Then Rs.MoveFirst() Do while NOT Rs.EOF %> <option value= "<% = Rs("ID") %>"><% = Rs("ID") %> - <% = Rs("ID") %></option> <% Rs.MoveNext() Loop End If Rs.Close() set Rs = nothing objCONN.Close() set objCONN = nothing %> </SELECT>
GuardaOriginariamente inviato da ALESSANDRO007
Devo fare una select che prenda i dati da una tabella presente in un data-base da dove comincio?
...
è una cosa irritante vedersi rispondere con un link, ma la domanda che hai fatto è troppo generica. Ed è una cosa che va imparata, tutta e bene, perchè altrimenti ti ritroverai ad aprire centinaia di post ed a elemosinare codice (che probabilmente nessuno ti farà)
http://asp.html.it/guide/leggi/65/guida-asp/
Grazie ad entrambi, provo e vi faccio sapere.
Appena inserisco la select la pagina mi va in errore dopo che la carica per mezzora.
Cominciamo con il codice:
<%
Dim categorie
Dim categorie_cmd
Dim categorie_numRows
Set categorie_cmd = Server.CreateObject ("ADODB.Command")
categorie_cmd.ActiveConnection = MM_inserisci_STRING
categorie_cmd.CommandText = "SELECT * FROM Categorie order by NomeCat ASC"
categorie_cmd.Prepared = true
Set categorie = categorie_cmd.Execute
categorie_numRows = 0
%>
<select name="Categoria" id="NomeCat" onchange="Richiesta('subcatsel.asp?cat='+this.valu e,'sub','sub');">
<%
While (NOT categoria.EOF)
%>
<option value="<%=(categoria.Fields.Item("IDCat").Value)%> " <%If (Not isNull(request.form("Categoria"))) Then If (CStr(categoria.Fields.Item("IDCat").Value) = CStr(request.form("Categoria"))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(categoria.Fields.Item("categoria").Value)%> </option>
<%
categoria.MoveNext()
Wend
If (categoria.CursorType > 0) Then
categoria.MoveFirst
Else
categoria.Requery
End If
%>
</select>
TENETE CONTO CHE LA TABELLA CATEGORIE E' RELAZIONATA CON LA TABELLA Sottocategorie nel data-base.
Per la quale devo ancora fare la dimm e tutto.
Dov'è l'errore?
verifica questo passaggio:
secondo me va scritto cosi:codice:<%If (Not isNull(request.form("Categoria"))) Then If (CStr(categoria.Fields.Item("IDCat").Value) = CStr(request.form("Categoria"))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(categoria.Fields.Item("categoria").Value)%>
codice:<% If (Not isNull(request.form("Categoria"))) Then 'Qui potresti scriverci qualcosa con un response nel caso la categoria sia nulla altrimenti non serve a niente. elseIf (CStr(categoria.Fields.Item("IDCat").Value) = CStr(request.form("Categoria"))) Then Response.Write("selected=""selected""") else Response.Write("") End if %> ><%=(categoria.Fields.Item("categoria").Value)%>
Cavicchi Andrea
Problemi con javascript, jquery, ajax clicca qui
Grazie x La risposta e i consigli Andrea proverò e verificherò, mi scuso per i ringraziamenti in ritardo ma sono stato influenzato.
![]()
Allora ora ho risolto con la select ma non memorizzo + i dati all'interno del data-base.
Che ho combinato ? Per chi non mi conosce, sappiate che sono un'audidatta, quindi vi prego di aiutarmi + con la pratica che termini tecnici li dove vi sia possibile. Grazie.
Codice pagina intera in due pagine altrimentri non entra :
Pagina 1)
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
' *** Edit Operations: declare variables - Dichiarazione variabili
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_inserisci_STRING
MM_editTable = "Aziende"
MM_editRedirectUrl = ""
MM_fieldsStr = "NomeAzienda|value|Email|value|Categoria|value|Sot toCateg|value|Newsletter|value
|Attivo|value|blocca|value|dataFA|value|Info|value "
MM_columnsStr = "NomeAzienda|',none,''|Email|',none,''|Categoria|' ,none,''|SottoCateg|none,none,NULL
|Newsletter|',none,''|Attivo|',none,''|blocca|',no ne,''|dataFA|',none,''|Info|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert")) <> "") Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values
(" & MM_dbValues & ")"
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim NomeAzienda__MMColParam
NomeAzienda__MMColParam = "1"
If (Request.QueryString("IDaz") <> "") Then
NomeAzienda__MMColParam = Request.QueryString("IDaz")
End If
%>
<%
Dim NomeAzienda
Dim NomeAzienda_numRows
Set NomeAzienda = Server.CreateObject("ADODB.Recordset")
NomeAzienda.ActiveConnection = MM_inserisci_STRING
NomeAzienda.Source = "SELECT * FROM Aziende WHERE IDaz = " + Replace(NomeAzienda__MMColParam, "'", "''") + ""
NomeAzienda.CursorType = 0
NomeAzienda.CursorLocation = 2
NomeAzienda.LockType = 1
NomeAzienda.Open()
NomeAzienda_numRows = 0
%>
<%
Dim NomeCat
Dim NomeCat_cmd
Dim NomeCat_numRows
Set NomeCat_cmd = Server.CreateObject ("ADODB.Command")
NomeCat_cmd.ActiveConnection = MM_inserisci_STRING
NomeCat_cmd.CommandText = "SELECT * FROM Categorie order by NomeCat ASC"
NomeCat_cmd.Prepared = true
Set NomeCat = NomeCat_cmd.Execute
NomeCat_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Nuova mail insert</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function controlla() {
document.onkeypress = keyhandler;
}
function keyhandler(e) {
if (document.layers){
Key = e.which;
}else{
Key = window.event.keyCode;
} if(Key==44){
window.event.keyCode=46;
//alert(Key);
}
}
function controllaNo() {
document.onkeypress = keyhandlerq;
}
function keyhandlerq(e) {
if (document.layers){
Key = e.which;
}else{
Key = window.event.keyCode;
} if(Key==46){
window.event.keyCode=46;
//alert(Key);
}
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' può contenere solo numeri.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('I campi segnati con *\n\nsono obbligatori!\n\n------------\n\nIl campo Categoria non può\n\ncontenere caratteri!');
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body>
[/b]</p>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="190"><tr><td width="100%" align="center">
<form id="inserisci" name="inserisci" method="POST" action="<%=MM_editAction%>">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="802" height="508"><tr><td colspan="2" style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="650" height="14"><p align="left">Inserimento di una nuova mail nella Mai-list</td><tr><tr><td colspan="2" style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="650" height="14">
<p align="left"></td></tr><tr><td width="221" style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" height="22">
<p align="left">email</td><td width="581" style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" height="22">
<p align="left"><input type="text" name="email" maxlength="50" style="width: 100%;" size="20"></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14">
<p align="left"></td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14">
<p align="left"></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="42">
<p style="margin-top: 0; margin-bottom: 0" align="left">Newsletter<p style="margin-top: 0; margin-bottom: 0" align="left"><font color="#FF0000">yes= abilitate alla ricezione</font><p style="margin-top: 0; margin-bottom: 0" align="left">
<font color="#FF0000">no= non abilitate alla ricezione</font></td>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="42"><p align="left"><select size="1"name="Newsletter"><option value="Yes">Yes</option><option value="No">No</option></select></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14"><p align="left"></td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14">
<p align="left"></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="22">
<p align="left">Nome Azienda</td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="22">
<p align="left"><input type="text" name="NomeAzienda" maxlength="50" size="30"></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14">
<p align="left"></td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14"><p align="left"></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="42"><p align="left">Attivo </p><p style="margin-top: 0; margin-bottom: 0" align="left">
<font color="#FF0000">yes= Attivo</font><p style="margin-top: 0; margin-bottom: 0" align="left"><font color="#FF0000">no= non attivo</font></td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="42"><p align="left"><select size="1" name="attivo">
<option value="Yes">Yes</option><option value="No">No</option></select></td></tr>
<tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14"><p align="left"></td>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14"><p align="left"></td></tr><tr>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="42">
<p align="left">Blocco invio </p><p style="margin-top: 0; margin-bottom: 0" align="left">
<font color="#FF0000">yes= Bloccato</font><p style="margin-top: 0; margin-bottom: 0" align="left"><font color="#FF0000">no= Attivo</font></td>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="42"><p align="left"><select size="1" name="blocca"><option value="No">No</option><option value="Yes">Yes</option>
</select></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14">
<p align="left"></td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14">
<p align="left"></td></tr><tr>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="52">
<p align="left">info azienda</td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="52">
<p align="left"><textarea rows="3" name="info" cols="71">Categoria azienda: c.a.p: Città: Località: </textarea></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14">
<p align="left"></td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14">
<p align="left"> </td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="22">
<p align="left">Categoria aziendale</td><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="22"><p align="left"><span style="font-size: 9pt">
<select name="Categoria" id="Categoria">
<%
While (NOT NomeCat.EOF)
%>
<option value="<%=(NomeCat.Fields.Item("IDCat").Value)%>" <%If (Not isNull(request.form("NomeCat"))) Then If (CStr(NomeCat.Fields.Item("IDCat").Value) = CStr(request.form("NomeCat"))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(NomeCat.Fields.Item("NomeCat").Value)%></option>
<%
NomeCat.MoveNext()
Wend
If (NomeCat.CursorType > 0) Then
NomeCat.MoveFirst
Else
NomeCat.Requery
End If
%>
</select>
</span>
</td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14"><p align="left"></td>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14"><p align="left"></td></tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="14"><p align="left">Sottocategoria</td>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="14"><p align="left"></td></tr><tr>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="221" height="20"><p align="left"></td>
<td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="581" height="20"> <p align="left"></td>
</tr><tr><td style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="802" colspan="2" height="92">
<p align="center"> Visualizza la Mail-list</td>
</tr> <tr><td colspan="2" align="right" style="font-style: Normal; font-variant: normal; font-weight: normal; font-size: 12px; font-family: Verdana" width="650" height="26">
<p align="center"><input type="submit" value="Inserisci">
</body>
</html>
<%
NomeAzienda.Close()
Set NomeAzienda = Nothing
%><%
NomeCat.Close()
Set NomeCat = Nothing
%>
LA PAGINA WEB E' UNICA OVVIAMENTE, E' SOLO PER UN FATTORE CHE NON ENTRAVA TUTTA IN UN POST.![]()