# \[PHP-\>Flash\]Problem with Arrays

**URL:** <https://forum.kirupa.com/t/php-flash-problem-with-arrays/183424>\
**Category:** flash\
**Created:** [March 26, 2006, 11:19pm UTC](https://forum.kirupa.com/t/php-flash-problem-with-arrays/183424 "2006-03-26T23:19:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [March 26, 2006, 11:19pm UTC](https://forum.kirupa.com/t/php-flash-problem-with-arrays/183424/1 "2006-03-26T23:19:16Z")

</div>

Basically what I’m doing is pulling information from a MySQL database and putting into a string and then loading that information into Flash using LoadVars. [I’ve used this tutorial to get me off the ground.](http://www.sephiroth.it/tutorials/flashPHP/news/)

[This is the PHP file (named posts.php) and [url=http://iamcolin.com/colin/php/phpstring.txt]here is the string is outputs.](http://iamcolin.com/colin/php/phpcode.txt)

All should be well and good from there, I think. There are four separate things for each entry’s information: ID, title, content, and date.

Here is the Actionscript code that loads it and displays it:

```auto

#include "textformat.as"
_root.site.createEmptyMovieClip("blogPage", 2);
loadEntries = new LoadVars();
loadEntries.load("http://localhost/fblog/posts.php");
loadEntries.onLoad = function() {
	myIDs = new Array();
	myTitles = new Array();
	myDates = new Array();
	myContent = new Array();
	for (var a in this) {
		//this is where the magic needs to happen
		//but I have no idea what to do!
		if (a != "onLoad") {
			myIDs.push(this[a]);
			trace(myIDs);
		}
	}
	var e:Number = 0;
	for (e=0;e<myIDs.length;e++) {
		_root.site.blogPage.attachMovie("entry", "entry"+e, 50+e);
		_root.site.blogPage["entry"+e]._y = 150*e;
		_root.site.blogPage["entry"+e].dateText.text = myDates[e];
		_root.site.blogPage["entry"+e].contentText.text = myContent[e];
		_root.site.blogPage["entry"+e].titleText.text = myTitles[e];
		_root.site.blogPage["entry"+e].idText.text = myIDs[e];
	}
};

```

It’s very primitive at the moment.

Here’s my problem, I have no idea how to pull apart the string to get the right information in the right spots.

What I want to do is split the string into it’s elements (ie. id0, title0, date0, content0, id1, etc.) and once I’ve accomplished that, I want to sort out each ID into an array called myIDs, and each title into an array called myTitles, etc.

It’s been a long while since I’ve dealt with actionscript and I’ve never loaded data from a MySQL database for use in Flash before, so any comments are welcome on how to best accomplish this.

Thanks a lot,  
Colin

Note to Mods: I put it in this forum because it really has very little to do with PHP and a lot to do with the Actionscript to get this working. If you feel this belongs somewhere better, go ahead and move it.

---

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [March 27, 2006, 2:18am UTC](https://forum.kirupa.com/t/php-flash-problem-with-arrays/183424/2 "2006-03-27T02:18:13Z")

</div>

Solved:

Here’s the AS code that did the trick:

```auto

myIDs = new Array();
myTitles = new Array();
myDates = new Array();
myContent = new Array();
var arrayLength = this.length-1;
for (i=arrayLength; i>=0; i--) {
	myIDs.push(this["id"+i]);
	myTitles.push(this["title"+i]);
	myDates.push(this["date"+i]);
	myContent.push(this["content"+i]);
}

```

Basically what I did was made the PHP file output a length value (gotten from $num\_rows):

print("&length=$num\_rows");

which is used by the Flash movie to determine how many entries there are, and then it puts the specified values into the correct arrays using the FOR loop.
