Ragazzi,
dovrei popolare delle select a cascata in php. Ho trovato un codice che sembra interessante, ma è in ASP... Qualcuno sa aiutarmi a convertirlo per un utilizzo in PHP???
Ecco il codice:
<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim strDataPath, strConnectString, objConnection, strCountry, strRegion, strCity, objRS, strSelected
'set connection strings for entire application
strDataPath = server.MapPath("NorthWind.mdb")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;"_
+ " Data Source= " & strDataPath & ";"_
+ " Mode=Share Deny None;User Id=admin;PASSWORD=;"
if not IsObject("ojbConnection") then
set objConnection=Server.CreateObject("ADODB.Connection")
objConnection.ConnectionTimeout = 15
objConnection.CommandTimeout = 10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if
strCountry = Request.Form("Country")
strRegion = Request.Form("Region")
strCity = Request.Form("City")
sub makeCountry()
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Country FROM Customers ORDER BY Country",objConnection,3,3
Response.Write("<option></option>" & VBCRLF )
do while not objRS.EOF
if objRS("Country") = strCountry then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Country") & "</option>" & VBCRLF )
objRS.MoveNext
loop
objRS.Close
set objRS=Nothing
end sub
sub makeRegion()
if strCountry <> "" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Region FROM Customers WHERE Country = '" & strCountry & "' ORDER BY Region",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Regions Found</option>")
else
Response.Write("<option>Select Region Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("Region") = strRegion then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Region") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Country First</option>")
end if
end sub
sub makeCity()
if strRegion <> "Select a Country First" AND strRegion <> "Select Region Now" AND strRegion <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT City FROM Customers WHERE Region = '" & strRegion & "' ORDER BY City",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Cities Found</option>")
else
Response.Write("<option>Select City Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("City") = strCity then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("City") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Region First</option>")
end if
end sub
%>
<SCRIPT LANGUAGE=javascript>
<!--
function submitCountry(){
var objForm = document.forms[0];
objForm.elements['Region'].selectedIndex=0;
objForm.elements['City'].selectedIndex = 0;
objForm.submit();
}
function submitRegion(){
var objForm = document.forms[0];
objForm.elements['City'].selectedIndex = 0;
objForm.submit();
}
function submitForm(){
var objForm = document.forms[0];
objForm.action = "processform.asp"
return true;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM action="MultiSelect.asp" method=POST id=form1 name=form1 onSubmit="return submitForm()">
<SELECT name="Country" onChange="submitCountry()">
<%call makeCountry%>
</SELECT><br>
<SELECT name="Region" onChange="submitRegion()">
<%call makeRegion%>
</SELECT><br>
<SELECT name="City">
<%call makeCity%>
</SELECT><br>
<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>
</HTML>
Vi prego aiutatemi!!! Grazie
p.s. Se avete un altro codice funzionante... E' sempre bene accetto!
dovrei popolare delle select a cascata in php. Ho trovato un codice che sembra interessante, ma è in ASP... Qualcuno sa aiutarmi a convertirlo per un utilizzo in PHP???
Ecco il codice:
<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim strDataPath, strConnectString, objConnection, strCountry, strRegion, strCity, objRS, strSelected
'set connection strings for entire application
strDataPath = server.MapPath("NorthWind.mdb")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;"_
+ " Data Source= " & strDataPath & ";"_
+ " Mode=Share Deny None;User Id=admin;PASSWORD=;"
if not IsObject("ojbConnection") then
set objConnection=Server.CreateObject("ADODB.Connection")
objConnection.ConnectionTimeout = 15
objConnection.CommandTimeout = 10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
objConnection.Open strConnectString
end if
end if
strCountry = Request.Form("Country")
strRegion = Request.Form("Region")
strCity = Request.Form("City")
sub makeCountry()
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Country FROM Customers ORDER BY Country",objConnection,3,3
Response.Write("<option></option>" & VBCRLF )
do while not objRS.EOF
if objRS("Country") = strCountry then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Country") & "</option>" & VBCRLF )
objRS.MoveNext
loop
objRS.Close
set objRS=Nothing
end sub
sub makeRegion()
if strCountry <> "" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT Region FROM Customers WHERE Country = '" & strCountry & "' ORDER BY Region",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Regions Found</option>")
else
Response.Write("<option>Select Region Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("Region") = strRegion then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("Region") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Country First</option>")
end if
end sub
sub makeCity()
if strRegion <> "Select a Country First" AND strRegion <> "Select Region Now" AND strRegion <>"" then
if not isObject("objRS") then
set objRS=Server.CreateObject("ADODB.RecordSet")
end if
if objRS.state <> 0 then
objRS.close
end if
objRS.Open "SELECT DISTINCT City FROM Customers WHERE Region = '" & strRegion & "' ORDER BY City",objConnection,3,3
if objRS.eof then
Response.Write("<option>No Cities Found</option>")
else
Response.Write("<option>Select City Now</option>" & VBCRLF )
do while not objRS.EOF
if objRS("City") = strCity then
strSelected = " Selected "
else
strSelected = ""
end if
Response.Write("<option" & strSelected & ">" & objRS("City") & "</option>" & VBCRLF )
objRS.MoveNext
loop
end if
objRS.Close
set objRS=Nothing
else
Response.Write("<option>Select a Region First</option>")
end if
end sub
%>
<SCRIPT LANGUAGE=javascript>
<!--
function submitCountry(){
var objForm = document.forms[0];
objForm.elements['Region'].selectedIndex=0;
objForm.elements['City'].selectedIndex = 0;
objForm.submit();
}
function submitRegion(){
var objForm = document.forms[0];
objForm.elements['City'].selectedIndex = 0;
objForm.submit();
}
function submitForm(){
var objForm = document.forms[0];
objForm.action = "processform.asp"
return true;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM action="MultiSelect.asp" method=POST id=form1 name=form1 onSubmit="return submitForm()">
<SELECT name="Country" onChange="submitCountry()">
<%call makeCountry%>
</SELECT><br>
<SELECT name="Region" onChange="submitRegion()">
<%call makeRegion%>
</SELECT><br>
<SELECT name="City">
<%call makeCity%>
</SELECT><br>
<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>
</HTML>
Vi prego aiutatemi!!! Grazie
p.s. Se avete un altro codice funzionante... E' sempre bene accetto!