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

**URL:** <https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176>\
**Category:** Uncategorized\
**Created:** [February 20, 2004, 3:35pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176 "2004-02-20T15:35:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![roady](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@roady](https://forum.kirupa.com/u/roady)\
**Post date:** [February 20, 2004, 3:35pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/1 "2004-02-20T15:35:56Z")

</div>

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:

```auto
<%
	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/](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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 20, 2004, 6:44pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/2 "2004-02-20T18:44:50Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 1:38pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/3 "2004-02-21T13:38:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 2:13pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/4 "2004-02-21T14:13:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 2:22pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/5 "2004-02-21T14:22:51Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 3:03pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/6 "2004-02-21T15:03:15Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 3:39pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/7 "2004-02-21T15:39:05Z")

</div>

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

```auto
<%
	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/](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]);

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 4:19pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/8 "2004-02-21T16:19:51Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 21, 2004, 5:20pm UTC](https://forum.kirupa.com/t/db-asp-loadvars-array-fmx/102176/9 "2004-02-21T17:20:59Z")

</div>

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/](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

```auto
<%
	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)
%>

```
