ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

ActionScript 3 and populating a DataGrid from a PHP script with data from a MySQL database.

Updated on October 18, 2010

Flash Actionscript3 DataGrid Component

ActionScript3 DataGrid Component being populated by a PHP script
ActionScript3 DataGrid Component being populated by a PHP script | Source

ActionScript 3 Datagrid Component populated by a PHP script.

I have to say I really struggled with this. I searched the forums, trawled the net, via Google of course, but there was no clear answer to my problem. I could find plenty of articles and forum posts on how to get data into the DataGrid, but it was all hard coded into the DataGrid component itself. There didn't seem to be anyone telling me how to get data from a MySQL database via a PHP script and populate the ActionScript3 DataGrid component.

So when I got it worked out, I put it into a tutorial so others can benefit from it.

I will share a little of the code that I use in the tutorial.

Firstly, I extract the data from the database via a simple PHP script.

Here is an example of one of the PHP scripts, I use to populate an Actionscript DataGrid component.


/*This section points to the file that
contains the database connection info
by keeping it in a separate file if you
need to move the program to another
server or database you only need to
make the change in one file rather than
making the changes in several places.*/

I keep the database login information in a separate file so that when I have lots of PHP files all accessing the database if I need to change the database, I only need to alter the setting in one place, otherwise I would have to alter the login details in each PHP script.

This is an example of the host_file.ini

$host = "localhost";
$user = "Database UserName";
$pass = "Database Password";
//This includes the the login details
for the databse
include "host_file.ini";
//This is  the SQL querty - just a
simple select query.
`Customer_table`.`cust_lastName` ASC";
//PHP reads the mysql data into an
$xx = mysql_query("$x")or
die("problem!" . mysql_error());
= mysql_fetch_row($xx);
/* The PHP code below formats the
database results into an array readable by the Flash
$i = 0;
$n = 0;
$results = mysql_query("$x");
$n= mysql_num_rows ($results);
while ($row = mysql_fetch_array
($results)) {
while (list ($key, $val) =
each ($row)) {
$r_string .= '&' . $key
. $i . '=' . stripslashes($val);
echo "i=".$i;
echo "&n=".$n;
echo $r_string;

The last lot of statements where it says the word “echo” this is where it sends the output to the Flash program and ActionScript takes over from there.

I found ActionScript 3 to be a lot more sensitive and quite different from its predecessor ActionScript 2.

I have put a lot of helpful tutorials on my website at and most of them are free so it would be a good place to start if your new to Flash and ActionScript.


    0 of 8192 characters used
    Post Comment

    • profile image

      raven 4 years ago

      where is the code of the flash?

    • profile image

      gerry 6 years ago

      Hi - good stuff but you haven't included the flash side of things. ie: receiving the variables from the php code.