ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

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";
$db="DatabaseName";
?>
<?
//This includes the the login details
for the databse
include "host_file.ini";
mysql_connect($host,$user,$pass);
mysql_select_db($db);
//This is  the SQL querty - just a
simple select query.
$x="SELECT
`Customer_table`.`cust_id_num`,
`Customer_table`.`cust_title`,
`Customer_table`.`cust_firstName`,
`Customer_table`.`cust_lastName`,
`Customer_table`.`cust_address`,
`Customer_table`.`cust_city`,
`Customer_table`.`cust_areacode`,
`Customer_table`.`cust_telephone`,
`Customer_table`.`cust_notes`,
`Customer_table`.`cust_date`,
`Customer_table`.`cust_dob`
FROM
`Customer_table`
ORDER BY
`Customer_table`.`cust_lastName` ASC";
 
//PHP reads the mysql data into an
array
 
$xx = mysql_query("$x")or
die("problem!" . mysql_error());
list($cust_id_num,$cust_title,$cust_firstName,$cust_lastName,$cust_address,$cust_city,
$cust_areacode,$cust_telephone,$cust_notes,$cust_date,$cust_dob)
= mysql_fetch_row($xx);
 
 
/* The PHP code below formats the
database results into an array readable by the Flash
datagrid.*/
 
$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);
}
$i++;
 
}
 
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 interactivewebconcepts.net and most of them are free so it would be a good place to start if your new to Flash and ActionScript.



Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      raven 

      5 years ago

      where is the code of the flash?

    • profile image

      gerry 

      7 years ago

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

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)