DB -> ASP -> LoadVars -> Array [fmx]

Hi, looked everywhere after a solution to this problem but it’s nowhere to be found.

Lets pretend that I want to write out some names from a DB and then get it with loadvars and then put it in an array for easy using later, how do I do this the best way ??

First thing first I have made an ASP file like this:

<%
	Dim objConnect, objRS, SQL, strConn, i
		Set objConnect	= Server.CreateObject("ADODB.Connection")
		Set objRS		= Server.CreateObject("ADODB.Recordset")
		
			strConn	= "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("db1.mdb")
			SQL		= "SELECT userFname, userEname FROM tblUser ORDER BY userFname Asc;"
			i		= 0
			
		objConnect.Open(strConn)
		objRS.Open(SQL), objConnect
		
		If Not objRS.EOF Then
			Do Until objRS.EOF
				Response.Write("&userFname"& i &"="& objRS(0) &"&userEname"& i &"=" & objRS(1))
				i = i +1
			objRS.MoveNext
			Loop
		End If
		
		objRS.Close: Set objRS = Nothing
		objConnect.Close: Set objConnect = Nothing

%>

it generates this
[COLOR=red]&userFname0=Fröken&userEname0=Fräken&userFname1=Kalle&userEname1=Banan&userFname2=Nisse&userEname2=Ljung&userFname3=Stina&userEname3=Ljung[/COLOR]

Now I schould take this string into flash.
the basic step is this.

[AS]_root.path = “http://localhost/flashDbTest/”;
var arrNames = new Array();
var myLoadVars = new LoadVars();
myLoadVars.load(_root.path + “getInfo.asp”);
myLoadVars.onLoad = fncLoadedInfo;

function fncLoadedInfo() {
[COLOR=red]WHAT SCOULD I DO HERE ??[/COLOR]
}[/AS]

[SIZE=3]So after a lot of text en explenations the main question is, how do I loop out this thing and put it all in an array =?[/SIZE]

How do you want the data to be placed in the array ? All the data in one array ? Or all the userFnames in one array and all the userEnames in another ?

hmm, good question, I guess the best way is to have it like this in a 2D-array

array[0][0] = Forename 1 person
array[0][1] = Forename 2 person
array[1][0] = Lastname 1 person
array[1][1] = Lastname 2 person

You know, for this purpose, I think it would be better to have your ASP script output the data in XML format. This will make it a lot easier to handle and manage.

hmm, maby…
but where can I find info about how to handle the information after I have loaded it with LoadVars ?
How Can I loop it and so on, any tips ?

good combination. (I spend my 2 days -yesterday and other working with DB-ASP-LoadVars…)

I was also downloading full database first, later found a better name.

for now, what you can do is, when you sending data to flash, use only 1 variable string and add some specific string between datas for ex : myString =ename1-oopp-sname1-oopp-ename2–…etc

Later on, you can parse them in flash with
myArray = new Array();
myArray = myString.split("-oopp-");

Hope it helps!

now I’ve been working a bit on the scripts, continued on your idea LastJedi.

So first I write out the string like this
[COLOR=red]userFname=Fröken,Kalle,Nisse,Stina,&userEname=Fräken,Banan,Ljung,Ljung[/COLOR]

To do this I use this asp-script

<%
	Dim objConnect, objRS, SQL, strConn, i
		Set objConnect	= Server.CreateObject("ADODB.Connection")
		Set objRS		= Server.CreateObject("ADODB.Recordset")
		
			strConn	= "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("db1.mdb")
			SQL		= "SELECT userFname, userEname FROM tblUser ORDER BY userFname Asc;"
			i		= 0
			
		objConnect.Open(strConn)
		objRS.Open(SQL), objConnect
		
		If Not objRS.EOF Then
			Do Until objRS.EOF
				strFname = strFname & objRS(0) & ","
			objRS.MoveNext
			Loop
			
			objRS.MoveFirst
			Do Until objRS.EOF
				strEname = strEname & objRS(1) & ","
			objRS.MoveNext
			Loop
		End If
		
		objRS.Close: Set objRS = Nothing
		objConnect.Close: Set objConnect = Nothing

			
			Response.Write("userFname="& strFname &"&userEname=" & strEname)
%>

And so finaly whe have the actionscript code
[AS]
System.useCodepage = true

_root.path = “http://localhost/flashDbTest/”;
var arrNames = new Array();
var myLoadVars = new LoadVars();
myLoadVars.load(_root.path + “getInfo.asp”);
myLoadVars.onLoad = fncLoadedInfo;

function fncLoadedInfo() {
myArray = new Array();
myArray[0] = this.userFname.split(",");
myArray[1] = this.userEname.split(",");
}[/AS]

This will result that you can print out a name with say person 2
trace(myArray[0][2] +" "+ myArray[1][2]);

hmmm …
in getInfo.asp you can return two strings:
UserEname=Fröken,Kalle,Nisse,Stina
UserFname=Fräken,Banan,Ljung,Ljung
which is myString=“UserEname=Fröken,Kalle,Nisse,Stina&UserFname=Fräken,Banan,Ljung,Ljung”

 In AS:

myArrayF = new Array();
myArrayE = new Array();
myArrayF = this.myString.split(",");
myArrayE = this.myString.split(",");

trace(myArrayF[0]+myArrayE[0]);

must return 1st person…

hehe, I have nothing to do so I develope my code a little more.
So with this you can take out info like name, city, phone with asp or php, then when flash have loaded the info it will sort it as.

array[0][0] = Fredrick
array[0][1] = Bäcker
array[0][2] = Gotheburg
array[0][3] = 0707-484132518

array[1][0] = Henning
array[2][1] = Petersson
array[3][2] = Malmö
array[4][3] = 4684-465484648

and so on.

[AS]System.useCodepage = true

_root.path = “http://localhost/flashDbTest/”;
var arrNames = new Array();
var myLoadVars = new LoadVars();
myLoadVars.load(_root.path + “getInfo.asp”);
myLoadVars.onLoad = fncLoadedInfo;

function fncLoadedInfo() {

// How many "posts" are there
strLength = this.userFname.split(",").length;

// Create new array and split up all strings
myArray 	= new Array(strLength);
arrFname 	= this.userFname.split(",");
arrEname 	= this.userEname.split(",");
arrCity 	= this.userCity.split(",");
arrPhone 	= this.userPhone.split(",");


// Loop and insert all user info
for(i=0; i&lt;strLength; i++){
	myArray* = new Array(4);
		myArray*[0] = arrFname*	// Firstname
		myArray*[1] = arrEname*	// Lastname
		myArray*[2] = arrCity*	// City
		myArray*[3] = arrPhone*	// Phone
}	

arrFname	= null;
arrEname	= null;
arrCity		= null;
arrPhone	= null;

}[/AS]

The string that asp generates is
[COLOR=red]userFname=Kalle,Linda,Nisse&userEname=Larsson,Persson,Ljung&userCity=Heberg,Partille,Falkenberg&userPhone=775-46585,646-45685,456-45675[/COLOR]

and heres the asp-page

<%
	Dim objConnect, objRS, SQL, strConn, i
		Set objConnect	= Server.CreateObject("ADODB.Connection")
		Set objRS		= Server.CreateObject("ADODB.Recordset")
		
			strConn	= "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("db1.mdb")
			SQL		= "SELECT userFname, userEname, userCity, userPhone FROM tblUser ORDER BY userFname Asc;"
			
			
		objConnect.Open(strConn)
		objRS.Open(SQL), objConnect
		
		If Not objRS.EOF Then
			Do Until objRS.EOF
				strFname = strFname & objRS(0) & ","
				strEname = strEname & objRS(1) & ","
				strCity = strCity & objRS(2) & ","
				strPhone = strPhone & objRS(3) & ","
			objRS.MoveNext
			Loop
		End If
		
		i = len(strFname)
		strFname = left(strFname, i-1)
		i = len(strEname)
		strEname = left(strEname, i-1)
		i = len(strCity)
		strCity = left(strCity, i-1)
		i = len(strPhone)
		strPhone = left(strPhone, i-1)
		
		
		objRS.Close: Set objRS = Nothing
		objConnect.Close: Set objConnect = Nothing

			
			Response.Write("userFname="& strFname &"&userEname=" & strEname &"&userCity=" & strCity &"&userPhone=" & strPhone)
%>