View Full Version : Getting Images from Database

10-05-2010, 01:26 AM
I currently have some images on my page that are static. I've never really used Actionscript and PHP so I don't really have a code snippet. Anyway, what I have is about 5 across and 4 rows down. What I would like to do is have that auto populate from images I've got stored on my server. Any help or guidance you could provide me would be great. Thanks in advance!

10-05-2010, 03:08 AM
I was able to pull in something from an external PHP site using the following code:

myData = new LoadVars();
myData.onLoad = function() {
myText_txt.text = this.mail;

This works great if I have static variables. However from my PHP page I will have more then one of the same variable. So for example:

$qry = "Select image from pics";
$result = mysql_query($qry);
while($resultset = mysql_fetch_array($result)){
echo $resultset['image'];

This could output 2 images or it could output 10 images. Will Actionscript just keep outputting the same variable multiple times? How can I achieve this?

Thanks in advance!

10-13-2010, 03:28 AM
you could easily use XML to pass the image list back to AS from PHP. in your PHP script, cycle through the result set and use SimpleXML to create some XML to send back to flash:

$xml = new SimpleXML("<response/>");

while( $r = mysql_fetch_assoc($result) )
$xml->addChild("image", $r['image']);


now in your AS code, you just have to loop thru the XML.image node and bada bing you have all your image results in a nice little package.