|
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"); $query1 = mysql_query("SELECT * FROM sites"); $queryString1 .= "title="; $queryStringFinal = $queryString1.$queryString2."&count=$count"; 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");
$query1 = mysql_query("SELECT * FROM sites WHERE id > ".$minvar); $queryString1 .= "title="; $queryStringFinal = $queryString1.$queryString2."&count=$count";
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).
You may also reach me at jsale37 (at) gmail.com |
12 Nov 2009 13:54:42 -0800