# Populating array from db (mysql, php) cocept

**URL:** <https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510>\
**Category:** Uncategorized\
**Created:** [September 7, 2004, 2:46pm UTC](https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510 "2004-09-07T14:46:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bape](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@bape](https://forum.kirupa.com/u/bape)\
**Post date:** [September 7, 2004, 2:46pm UTC](https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510/1 "2004-09-07T14:46:41Z")

</div>

hey there people, i was just wondering how to do this. I want my table from the database in an array in flash. What is the concept of this, should i send a string with each variable/object and have flash sort it out into a array or can you just let php make the array and send that over?  
Could you guys help me out with this, or point me to a tutorial (have looked but cant find the right one)?

(using twodimensional arrays)

---

<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:** [September 7, 2004, 3:43pm UTC](https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510/2 "2004-09-07T15:43:21Z")

</div>

I would either  
create a txt file in PHP containing a string with each variable/object separated by a comma(or any sign )so can split the string into an array once loaded into Flash

or

create an XML file in PHP and load it into flash.

SHO

---

<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:** [September 7, 2004, 4:13pm UTC](https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510/3 "2004-09-07T16:13:30Z")

</div>

Depending on what your end means are; I would populate an array in PHP using a delimination, as suggested in the previous post and send that data over to flash and stuff it in a variable. Then you can extropolate it in flash using whatever method you choose. Need deatils on how to do this?

---

<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:** [September 8, 2004, 10:55am UTC](https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510/4 "2004-09-08T10:55:51Z")

</div>

> [@aknatn](#):
>
> Depending on what your end means are; I would populate an array in PHP using a delimination, as suggested in the previous post and send that data over to flash and stuff it in a variable. Then you can extropolate it in flash using whatever method you choose. Need deatils on how to do this?

Yes some details would be great, cause this sounds pretty complicated to me…  
Thanx for the replies so far

---

<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:** [September 8, 2004, 5:26pm UTC](https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510/5 "2004-09-08T17:26:39Z")

</div>

Here is an example using PHP, MySql, and the loadVars.onLoad method

Here is the PHP

```auto

<?
//link up to mysql
$username="your username";
$password="your password";
$database="glasses";
$link = @mysql_connect("localhost",$username,$password);

    //prefix variable for flash interpolation
print "output=";

mysql_select_db($database, $link) or die ("Unable to select database");
    // Request the text of all the glasses 
    $result = @mysql_query("SELECT ID, name FROM 
glass"); 

    // Display the text of each Shotglass
$num_rows = mysql_num_rows($result);
    while ( $row = mysql_fetch_array($result) ) { 
      $glassid = $row["ID"]; 
      $glasstext = $row["name"];
    
    // Variable to send to flash notice the "|" that delimites the values
     print "$glasstext|";
  
    }
    
     
   
   
?>

```

Here is the flash

```auto

// create new load vars
varReceiver = new LoadVars();
// loads the variables, this must be a url
varReceiver.load("http://structure.myftp.org/flash/dev/glassesLoadTest.php");
//assisgns the callback funtion
varReceiver.onLoad = handleLoad;
//defines the callback function and proccess whatever you want to do with the variables
function handleLoad (success) {
	if (success) {
		trace(this.output);
	}else{
		trace("no variables were found");
	}
}

```

Hope that helps :thumb:

---

<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:** [September 13, 2004, 9:54am UTC](https://forum.kirupa.com/t/populating-array-from-db-mysql-php-cocept/63510/6 "2004-09-13T09:54:45Z")

</div>

Ok i have got this working now; getting data from the database in myArray=bla|bla2|bla3 form and converting it to an array with the split function. Now for another more difficult part. How do i get a twodimensional array?  
I have these fields in my database: name, age, place  
and I want to get this array (with a loop so if there are more persons in it the array will be bigger):

```auto

myArray=[["john","33","london"],["mark","25","bristol"]]

```
