Graphic Design: 

 
Flash Distraction
of the Week

About the Flash
Video Gallery

GCCCD Blackboard

GD 222
Home
Syllabus
Schedule
News
Labs
Videos
Flash Resources
Web Dev Resources

 

GD 222 Flash Web Animation - Spring, 2009
Online Course
http://www.cuyamaca.edu/jeff.sale/gd222/

Flash PHP MySQL Example
Baro

Example 1

Click the "Get All" button in the Flash movie below to query a MySQL database and load the contents into a Flash text object.

Here are the files to run this example yourself:

Download the MySQL database table file sites.sql

Download the original Flash file getall.fla

Step 1: Copy and paste the following PHP code into a new text file named "getall.php". Be sure to change the parameters in the first two lines to conform to your own MySQL database:

<?php

mysql_connect("your_database_host_server","login", "password");
mysql_select_db("your_database_name");

$query1 = mysql_query("SELECT * FROM sites");
$count = 0;

$queryString1 .= "title=";
$queryString2 .= "&link=";


while($row=mysql_fetch_array($query1)) {
$queryString1 .= $row[title].":";
$queryString2 .= $row[link].":";
$count++;
}

$queryStringFinal = $queryString1.$queryString2."&count=$count";
echo $queryStringFinal;

mysql_close();
?>

Step 2: Create your table in MySQL by importing the file "sites.sql" into your database to create the "sites" table

Step 3: Copy and paste the PHP code above into a text file. Change the lines of code beginning with "mysql_connect" and "mysql_select_db" to those values appropriate to your database. Upload this file to your server and name it "getall.php". Test this file in a browser to confirm that it is working.

Step 4: Publish the "getall.fla" Flash file and upload it to the same directory where your "getall.php" file is. Click the "Get All" button to test it! Hopefully you will see text displayed below the button.

 

Example 2

A more advanced query method is to include a parameter in your query for more specific and selective results. To do this we us the onSendAndLoad command in Flash. For this example, you will specify a minimum value for your database query so only those entries with id numbers above the value you entered will be displayed.

Download the original Flash file getsome.fla for this example.

Repeat the steps above but instead copy the text in bold below, paste it into a text file and save your file as "getsome.php".

<?php

mysql_connect("your_database_host_server","login", "password");
mysql_select_db("your_database_name");


$minvar = $HTTP_POST_VARS['minvar'];

$query1 = mysql_query("SELECT * FROM sites WHERE id > ".$minvar);
$count = 0;

$queryString1 .= "title=";
$queryString2 .= "&link=";


while($row=mysql_fetch_array($query1)) {
$queryString1 .= $row[title].":";
$queryString2 .= $row[link].":";
$count++;
}

$queryStringFinal = $queryString1.$queryString2."&count=$count";
echo $queryStringFinal;

mysql_close();
?>

 

That's it!!

Here's a link to download Moodle-In-A-Box, an all-in-one installation of Apache, PHP, MySQL, and Moodle (for Windows only).

 

 

Jeff Sale

E-mail: jeff.sale (at) gcccd.edu
Phone: 619-660-4000
Fax: 619-660-4399
Graphic Design, Cuyamaca College
You may also reach me at jsale37 (at) gmail.com

 

 

12 Nov 2009 13:54:42 -0800